#190557 - 2008-11-12 11:33 AM
copy files by creation date
|
serr57
Fresh Scripter
Registered: 2008-11-10
Posts: 18
|
Hello,
I use Kixtart since several time (only for login scripts), and I have to do a file operation, here is my target.
an automatic process generate a pdf file in a dedicated folder. Those pdf are not always daily generated
I have to do a script that make a copy of each pdf on a network share in fonction of it's creation date, in a folder with its date (it is possible to have several files with same creation date)
When this file is copied the source must be deleted each one by one after a size control.
If I can do simple scripts, I am a stranger in this methodology (I'm not sure that it is possible)
But may be you can help me or give me a cap
Thanks a lot
serr57
|
Top
|
|
|
|
#190565 - 2008-11-13 03:59 PM
Re: copy files by creation date
[Re: serr57]
|
serr57
Fresh Scripter
Registered: 2008-11-10
Posts: 18
|
Nobody can help me ? I have tried with getfiletime, but I haven't got results May be it is not possible to do this or by a very complicated way
serr57
|
Top
|
|
|
|
#190571 - 2008-11-13 06:07 PM
Re: copy files by creation date
[Re: serr57]
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
What did you get for results?
The example in the Docs should serve you well.
Can you show us your code?
Thanks,
Kent
|
Top
|
|
|
|
#190603 - 2008-11-16 05:50 PM
Re: copy files by creation date
[Re: Kdyer]
|
serr57
Fresh Scripter
Registered: 2008-11-10
Posts: 18
|
Hello
Sorry to don't have answer earlier I have tested this script, but it does nothing .... (I don't understand $File variable)
After lots of search on internet here is the code I used but there several error yet Break OFF Debug "ON" SetConsole ("show")
;Use Y: "\\Myserver\share\"
$Swift = "C:\testswift1\" $Acores = "C:\testswift2\"
; Scan dir for list of files
$nextfile = Dir("$Swift\*.*")
While $nextfile <> ""
$creationdate = GETFILETIME($nextfile, 1, 2)
$dirname = TRIM(JOIN(SPLIT(SUBSTR($creationdate, 1, 10), '/'), '-')) $outputfile = $Acores + "\" + $dirname + "\" + $nextfile
If Exist ('$Acores' + $dirname)
Copy $nextfile $outputfile
ELSE
MD $dirname Copy $nextfile $outputfile
ENDIF
;$nextfile = Dir()
Loop
;Use Y: /DEL
|
Top
|
|
|
|
#190605 - 2008-11-16 06:29 PM
Re: copy files by creation date
[Re: Gargoyle]
|
serr57
Fresh Scripter
Registered: 2008-11-10
Posts: 18
|
Hey what a quick answer congratulation,
When I used Debug "on", It does nothing only the loop I think there is something wrong in my code.
I don't know how to have more information on what does the script Do I have to redirect on an output txt file like in dos (> C:\folder\log.txt)?
|
Top
|
|
|
|
#190607 - 2008-11-16 08:52 PM
Re: copy files by creation date
[Re: Gargoyle]
|
serr57
Fresh Scripter
Registered: 2008-11-10
Posts: 18
|
Really many thanks When I execute this script, it is normal that it doesn't find the folder I don't why, the folder was created on my desktop, and not in "C:\testswift2\"
Is it a variable definition problem ?
Here is the debug log
serr57
? FTest2.kix 0. In the while loop ssfully.date = 2008/09/20 17:05:15 Return code was The operation completed succe Dirname = 2008-09-20 Return code was The operation completed successfully. The output file = C:\testswift2\\2008-09-20\.Directory did not exist ts.e Directory command returned Cannot create a file when that file already exis File Copy results The system cannot find the path specified. In the while loop
|
Top
|
|
|
|
#190738 - 2008-11-24 04:51 PM
Re: copy files by creation date
[Re: Gargoyle]
|
serr57
Fresh Scripter
Registered: 2008-11-10
Posts: 18
|
Many thanks but even after correction and lots of tests, it doesn't match.
I have tested you first proposition, with DirPlus, I have used your procédure to get more information in debuging mode, and it appears that dirplus is not reconised, is there some thing to do before using UDF library?
Here is my debug :
For each $File in $FileArray
0\\myserver\myshare\*.pdfdirplus
My script
Break OFF Debug "ON" SetConsole ("show")
$FileArray = dirplus("\\myserver\share\*.pdf") $FileArray ? For each $File in $FileArray $Date = Join(Split(Split(GetFileTime($File)," ")[0],"/"),"") If Not Exist ("C:\ZZArchivesSwiftPDF\"+$Date) MD "C:\PDF\"+$Date EndIf Copy $File "C:\PDF\"+$Date+"\" ;Del $File Next
In debug mode the windows close itself after "For each $File in $FileArray" fonction
£Any idea, mine is dirplus related,but I don't know how to use udf library, activation and so on ....
Tranks again
serr57
|
Top
|
|
|
|
#190745 - 2008-11-24 08:07 PM
Re: copy files by creation date
[Re: BradV]
|
serr57
Fresh Scripter
Registered: 2008-11-10
Posts: 18
|
Sorry I don't understand, I should copy this :
Function DirPlus($path,optional $Options, optional $f, optional $sfflag)
If not vartype($f) DIM $f EndIf
If not vartype($sfflag) DIM $sfflag EndIf
DIM $file, $i, $temp, $item, $ex1, $mask,$mask1,$maskArray,$maskarray1,
$ex2, $code, $CodeWeight, $targetWeight, $weight, $masktrue
DIM $tarray[0]
$ex1 = SetOption(Explicit,on)
$ex2 = SetOption(NoVarsInStrings,on)
$codeWeight = 0
If not Exist($path)
$temp = SetOption(Explicit,$ex1)
$temp = SetOption(NoVarsInStrings,$ex2)
Exit @ERROR
EndIf
If not vartype($f)
$f = CreateObject("Scripting.FileSystemObject").getfolder($path)
EndIf
If @ERROR
$temp = SetOption(Explicit,$ex1)
$temp = SetOption(NoVarsInStrings,$ex2)
Exit @ERROR
EndIf
For Each $temp In Split($options,"/")
$temp=Trim($temp)
Select
Case left($temp,1) = "s"
If not vartype($sfflag)
If Val(right($temp,-1)) = 0
$sfflag = -1
Else
$sfflag = Val(right($temp,-1))
EndIf
EndIf
Case Left($temp,1) = "a"
Select
Case Right($temp,-1)="d"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 16 " ;"if $file.type = 'File Folder' "
Case Right($temp,-1)="-d"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 16)=0 " ;"if $file.type <> 'File Folder' "
Case Right($temp,-1)="s"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 4 "
Case Right($temp,-1)="-s"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 4)=0 "
Case Right($temp,-1)="h"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 2 "
Case Right($temp,-1)="-h"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 2)=0 "
Case Right($temp,-1)="r"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 1 "
Case Right($temp,-1)="-r"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 1)=0 "
Case Right($temp,-1)="a"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 32 "
Case Right($temp,-1)="-a"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 32)=0 "
EndSelect
$code = $temp + "$weight=$weight+1 endif" +@CRLF + $code
Case Left($temp,1) = "m"
$maskarray = Split(Right($temp,-2),"|")
$codeweight = $codeweight + 1
$code = "$masktrue=0 for Each $mask in $maskarray if instr($file.name,$mask) $masktrue=1 " +
"EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code
Case Left($temp,1) = "f"
$maskarray1 = Split(Right($temp,-2)," ")
$codeweight = $codeweight + 1
$code = "$masktrue=0 for Each $mask1 in $maskarray1 if substr($file.name,Instrrev($file.name,'.')+1)" +
"=$mask1 $masktrue=1 EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code
EndSelect
Next
$code = "$weight = 0 $targetWeight = " + $codeweight + @CRLF + $code
$code = $code + "if $weight = $targetweight Exit 1 endif"
For Each $file In $f.subfolders
If Execute($code)
$tarray[$i] = $file
$i = $i + 1
ReDIM preserve $tarray[$i]
EndIf
If $sfflag
$temp = dirplus($file,$options,$file,$sfflag-1)
For Each $item In $temp
$tarray[$i] = $item
$i = $i + 1
ReDIM preserve $tarray[$i]
Next
EndIf
Next
For Each $file In $f.files
If Execute($code)
$tarray[$i] = $file
$i = $i + 1
ReDIM preserve $tarray[$i]
EndIf
Next
If $i
ReDIM preserve $tarray[$i-1]
$i=0
Else
$tarray = 0
EndIf
$dirplus = $tarray
$temp = SetOption(Explicit,$ex1)
$temp = SetOption(NoVarsInStrings,$ex2)
Exit @ERROR
EndFunction
into my script ?
serr57
Edited by Benny69 (2008-11-24 08:31 PM) Edit Reason: I modified this post to include Code Tags
|
Top
|
|
|
|
#190747 - 2008-11-24 11:07 PM
Re: copy files by creation date
[Re: serr57]
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
|
Top
|
|
|
|
#190846 - 2008-12-04 04:57 PM
Re: copy files by creation date
[Re: Bryce]
|
serr57
Fresh Scripter
Registered: 2008-11-10
Posts: 18
|
Hello,
I have finished my script, it works very well, and does what ever I would If it can help somebody here is it
;Begin of Script
Break ON
Debug "OFF"
SetConsole ("show")
$Swift = "\\myserver\myshare"
$Acores = "\\myserver\myshare"
; Scan directory for files listing
$nextfile = Dir("$Swift\*.pdf")
While $nextfile <> "" and @error = 0
; Variables creation to get files time, Using 10 string characters of the date, define the output
$creationdate = GETFILETIME($Swift + "\" + $nextfile, 0, 2)
$dirname = TRIM(JOIN(SPLIT(SUBSTR($creationdate, 1, 10), '/'), '-'))
$outputfile = $Acores + "\" + $dirname + "\" + $nextfile
; Folder existance checking before copy
IF NOT EXIST ($Acores + "\" + $dirname)
MD $Acores + "\" +$dirname
ENDIF
IF NOT EXIST ($outputfile)
Copy $Swift + "\" + $nextfile $outputfile
DEL $Swift + "\" + $nextfile
ENDIF
$nextfile = DIR ()
Loop
EXIT
;end of Script
Many thanks for your help
serr57
Edited by Benny69 (2008-12-04 05:04 PM) Edit Reason: Added Code Tags
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 515 anonymous users online.
|
|
|