Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using COP command
#3
Function BackupFiles
Code:
Copy      Help
;/
function $source $destFolder [ifExists] [flags] ;;ifExists - 0 replace, 1 dialog, 2 rename, 3 error, 4 do nothing, 5 replace if source is newer;  flags: 1 no intermediate folder

;Copies files to a folder.
;Error if fails to copy a file.

;source - file, folder or list of files and/or folders. Also can be drive(s). Error if does not exist.
;destFolder - destination folder. The function creates it if does not exist.


ARRAY(str) aS aD
GetFileCopyPaths source destFolder aS aD flags

str sS(aS) sD(aD)
;out "---- src ----[]%s[]---- dest ----[]%s" sS sD

sel ifExists
,case 0
,cop- sS sD
,
,case 1
,cop sS sD
,
,case 2
,cop+ sS sD
,
,case [3,4,5]
,int i
,for i aD.len-1 -1 -1
,,if(!dir(aD[i])) continue
,,sel ifExists
,,,case 3
,,,end "Destination file '%s' already exists" 0 aD[i]
,,,
,,,case 5
,,,long d1 d2
,,,memcpy &d2 &_dir.fd.ftLastWriteTime 8
,,,dir aS[i]
,,,memcpy &d1 &_dir.fd.ftLastWriteTime 8
,,,if(d1>d2) continue
,,
,,aD.remove(i)
,,aS.remove(i)
,,
,sS=aS; sD=aD
,;out "---- src ----[]%s[]---- dest ----[]%s" sS sD
,if(aD.len) cop- sS sD
,
,case else end ES_BADARG

err+ end _error

Function GetFileCopyPaths
Code:
Copy      Help
;/
function $source $destFolder ARRAY(str)&aSources ARRAY(str)&aDestinations [flags] ;;flags: 1 no intermediate folder

;Gets paths of all source and destination files to be used in a copy operation.

;source - file, folder or list of files and/or folders. Also can be drive(s). Error if does not exist.
;destFolder - destination folder.
;aSources - receives full paths of all files (but not folders) to be copied.
;aDestinations - receives full paths of all files (but not folders) that would be created in destFolder after a copy opertion.


aSources=0; aDestinations=0

str sListS sListD sDF sDF2 s1 s2
sDF.expandpath(destFolder); sDF.rtrim("\")

foreach s1 source
,s2.expandpath(s1); s2.rtrim("\")
,if(!dir(s2 2)) end "source not found"
,
,if _dir.fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY
,,if flags&1
,,,sDF2=sDF
,,else
,,,int i=findcr(s2 '\')
,,,if(i>0) sDF2.from(sDF s2+i)
,,,else sDF2.from(sDF "\" _s.left(s2 1)) ;;E:
,,
,,Dir d
,,foreach(d _s.from(s2 "\*") FE_Dir 0x4)
,,,str sPath=d.FileName(1)
,,,aSources[]=sPath
,,,aDestinations[].from(sDF2 sPath+s2.len)
,else
,,aSources[]=s2
,,aDestinations[].from(sDF s2+findcr(s2 '\'))


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)