#36442 - 2003-02-13 02:11 PM
Not overwrite files (... copy multiple files of same name to one location)
|
Mike Duhwald
Fresh Scripter
Registered: 2003-01-13
Posts: 40
|
Hi, the copy command overwrite files of the same name in the destination dir - for example test.doc.
How can I prevent copy to do this so the files will be renamed - for example test1.doc, test2.doc etc.
Regards Mike
(MCA: complete subject) [ 14. February 2003, 22:48: Message edited by: MCA ]
|
|
Top
|
|
|
|
#36444 - 2003-02-13 06:24 PM
Re: Not overwrite files (... copy multiple files of same name to one location)
|
Mike Duhwald
Fresh Scripter
Registered: 2003-01-13
Posts: 40
|
Hi, now I got this script:
code:
$Path=("C:\Backup\Test\") Enumdir("$Path") ; Function EnumDir($p) If not $p Return Endif Dim $file $file = Dir($p) While $file <> "" and @Error = 0 If not ($file = "." OR $file = "..") ; ? $p +"\" +$file ; If GetFileAttr($p+"\"+$file) & 16 EnumDir($p+"\"+$file) EndIf EndIf $file = DIR() Loop Endfunction
Can you tell me how I must modify it for the filecopy e.g. that the files are renamed if existend?
regards mike
|
|
Top
|
|
|
|
#36445 - 2003-02-13 10:50 PM
Re: Not overwrite files (... copy multiple files of same name to one location)
|
Waltz
Seasoned Scripter
Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
|
Mike... It ain't perfect, but it will get you started...
code:
; test.kix $Source = "C:\kixtest\source\" $Target = "C:\kixtest\target\" $TargetCount = 0 $File = "Test.html" ; $SourceFileName = Dir($Source,0) ; get the first source file While $SourceFileName <> "" AND @ERROR = 0 ; loop until done If $SourceFilename = $File ; if the filename is 'test.html' ; ; get the current count of 'test*.html' files in the target folder $TargetFileName = Dir($Target,1) While $TargetFileName <> "" AND @ERROR = 0 If Left($TargetFileName,4) == Left($File,4) AND Right($TargetFileName,4) == Right($File,4) $TargetCount = $TargetCount + 1 Endif $TargetFileName = Dir("",1) Loop ; ; give the source file a new name based on the current file count in the target folder $NewName = Left($File,4)+Cstr($TargetCount+1)+"."+Right($File,4) ; ; copy the source file to the target folder and then rename it $Cmdstr='%comspec% /c Rename $Target$File $NewName' Copy $Source+$File $Target Shell $Cmdstr Endif ; $SourceFileName = Dir("",0) ; get the next source file Loop ; end of test.kix
_________________________
We all live in a Yellow Subroutine...
|
|
Top
|
|
|
|
#36446 - 2003-02-14 08:01 AM
Re: Not overwrite files (... copy multiple files of same name to one location)
|
Mike Duhwald
Fresh Scripter
Registered: 2003-01-13
Posts: 40
|
Thank you - how can I go through all subdirectories in $Source?
Regards Mike
|
|
Top
|
|
|
|
#36448 - 2003-02-14 09:19 AM
Re: Not overwrite files (... copy multiple files of same name to one location)
|
Mike Duhwald
Fresh Scripter
Registered: 2003-01-13
Posts: 40
|
Hi NTDOC, I wrote a script that is saving the favorites of the internet explorer and netscape navigator. I want to save the netscape bookmarks twice. once in a directory named after the workstation and on the other hand in the root of the backup directory. In the workstation directory the files should be overwritten - in the root directory the files should continously renamed bookmark1.htm, bookmark2.htm and so on. I got problems with the last task and would appreciate any help:
code:
Break On Dim $iAttempts Dim $sServer Dim $sDrive Dim $sLogin Dim $sPassword $iAttempts=3 $sDrive="X:" $sServer="\\servername"
While($iAttempts) "Username + Password... " ? ?; (" "noch " + $iAttempts + " Versuche möglich)" ? $sLogin=GetString(" Username: ") ? $sPassword=GetString(" Password: ","*") ? Use $sDrive $sServer + "\" + $sLogin + "$$" /USER:$sLogin /PASSWORD:$sPassword If @ERROR "ERROR: @ERROR @SERROR" ? ? $iAttempts=$iAttempts-1 Else $iAttempts=0 EndIf Loop
SHELL "%COMSPEC% /c XCOPY /d /s /e /q " + "%USERPROFILE%" + "\Favorites\*.* " + $sDrive + "\IE\Favorites\"
$folder=$sDrive + "\Netscape\"+@WKSTA If Exist ($folder) = 0 MD $folder If @error <> 0 ? "Error "+@error+" "+@serror Endif Endif
$search_key = "c:\bookmark.htm" $Save = $sDrive + "\Netscape\@WKSTA" $Save2 = $sDrive + "\Netscape\"
If (Exist("%temp%\bookmark.tmp") = 1) DEL %temp%\bookmark.tmp Endif SHELL "%comspec% /e:1024 /c dir " + $search_key + " /a /b /s >%temp%\bookmark.tmp" SHELL "%comspec% /e:1024 /c echo -Ende der Liste- >>%temp%\bookmark.tmp" If (Exist ("%temp%\bookmark.tmp") = 1) If Open(1,"%temp%\bookmark.tmp") Endif $found="no" $count=0 While ($found = "no") $result=ReadLine(1) If (@error <> 0) OR (InStr($result,"-End of List-") <> 0) $found="yes" Else $count=$count+1 If Open(2, $result) Endif GOSUB Save_Favorites If Close(2) Endif Endif Loop If Close(1) Endif Endif DEL %temp%\bookmark.tmp Exit
:Save_Favorites If (Substr($Save,Len($Save),1) = "\") $Save=Substr($Save,1,Len($Save)-1) Else If (Substr($Save2,Len($Save2),1) = "\") $Save2=Substr($Save2,1,Len($Save2)-1) Endif If ($count > 0) ; If ($count > 1) $target=$Save + "\bookmark"+$count+".htm" $target2=$Save2 + "\bookmark"+$count+".htm" Else $target=$Save + "\bookmark.htm" $target2=$Save2 + "\bookmark.htm" EndIf
COPY $result $target /h COPY $result $target2 /h If (@error <> 0) ? "Warning: error @error (@serror)" Endif RETURN
Exit 0
Function EnumDir($p) If not $p Return Endif Dim $f $f = DIR($p) While $f <> "" and @Error = 0 If not ($f = "." OR $f = "..") Endif $f = Dir() Loop Endfunction
Function GetString($sPrompt,Optional $sPassChar) Dim $cKey $sPrompt While("True") Get $cKey Select Case $cKey=Chr(8) If $GetString<>"" Chr(8) " " Chr(8) $GetString=SubStr($GetString,1,Len($GetString)-1) EndIf Case $cKey=Chr(13) If $GetString<>"" Return EndIf Case Asc($cKey)>=32 AND Asc($cKey)<=127 $GetString=$GetString+$cKey If $sPassChar<>"" $sPassChar Else $cKey EndIf Case "True" EndSelect Loop EndFunction
Regards Mike
|
|
Top
|
|
|
|
#36450 - 2003-02-14 10:46 PM
Re: Not overwrite files (... copy multiple files of same name to one location)
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear,
Indeed it looks like a cross-post, but some things aren't the same. Only the way of asking is different. Other topic contains the required modification to a script he already knows. greetings.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|