Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BACKUP
#1
Guys,

How can I copy all modified files (from documents) in the last 24h to a Backup folder?

I would need also to input the modification date (yyyy.MM.dd) in the end of the file name.

Thanks a lot for helping.
#2
Macro Macro2726
Code:
Copy      Help
str folder.expandpath("$Documents$")
str files="*" ;;all
str backupFolder.expandpath("C:\Backup")

;get array of files modified in the last 24 hours. Look in subfolders too (flag 4).
ARRAY(str) aFiles aDates
DateTime t.FromComputerTime; t.AddParts(0 -24) ;;get time now minus 24 hours
Dir d
foreach(d F"{folder}\{files}" FE_Dir 4)
,str path=d.FullPath
,;out path
,;str name=d.FileName
,DateTime tm=d.TimeModified
,if(tm<t) continue ;;modified earlier
,;out path
,aFiles[]=path
,aDates[].timeformat("-{yyyy.MM.dd}" tm)

;backup
if(!aFiles.len) out "0 files found"; ret
mkdir backupFolder
int i
for i 0 aFiles.len
,str& r=aFiles[i]
,lpstr relPath=r+folder.len
,lpstr e=PathFindExtension(relPath)
,str file2.fromn(backupFolder -1 relPath e-relPath aDates[i] -1 e -1)
,out F"COPY from to:[]{r}[]{file2}"
,cop- r file2

;view results
run backupFolder
#3
Perfect!!!!!
Thanks a lot! Big Grin
#4
Thank you Gintaras for this perfect routine. I was in need of two modifications : (a) to omit the time extension (ARRAY aDates), which it was done successfully and (b) to modify the output path, in order to be able, following a zip operation (7-zip), to restore at the original locations. However, I failed to set up properly the value of "file2" to this end. Any advice is mostly appreciated.

Let me, please, extend my questions by asking whether this routine could co-operate qith QM zip command. If this is feasible, then what is the main differences as compared to the zip with 7-zip. Is it likely that the compression ration when using 7-zip is much better.

Thank you for your attention, Best regards,
#5
Dear Gintaras,

I found a solution for (b) above, which it works :

1. Define a string
Quote:str tso="C:"
2. Replace statement "lpstr relPath" by
Quote: lpstr relPath=r+tso.len

Any further advice is welcome.


Forum Jump:


Users browsing this thread: 1 Guest(s)