Page 1 of 1 1
Topic Options
#36442 - 2003-02-13 02:11 PM Not overwrite files (... copy multiple files of same name to one location)
Mike Duhwald Offline
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
#36443 - 2003-02-13 02:20 PM Re: Not overwrite files (... copy multiple files of same name to one location)
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
You can't change the behaviour of the copy command - it overwrites without warning. You need to consider following Jen's advice in response to one of your previous posts and rename the files. Jen's pseudo code is what you need to work on. [Smile]
_________________________
We all live in a Yellow Subroutine...

Top
#36444 - 2003-02-13 06:24 PM Re: Not overwrite files (... copy multiple files of same name to one location)
Mike Duhwald Offline
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 Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Mike...
It ain't perfect, but it will get you started... [Smile]
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 Offline
Fresh Scripter

Registered: 2003-01-13
Posts: 40
Thank you - how can I go through all subdirectories in $Source?

Regards
Mike

Top
#36447 - 2003-02-14 08:46 AM Re: Not overwrite files (... copy multiple files of same name to one location)
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Mike,

What exactly is it you're wanting to do? KiXtart is cool and all, but there are many programs already out there that are much faster as they are compiled programs for the task at hand.

What is wrong with even shelling from KiXtart out to the XCOPY command?

Since I didn't see any of your other posts, I'm trying to imagine what it is you're wanting to do exactly.

Top
#36448 - 2003-02-14 09:19 AM Re: Not overwrite files (... copy multiple files of same name to one location)
Mike Duhwald Offline
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
#36449 - 2003-02-14 08:54 PM Re: Not overwrite files (... copy multiple files of same name to one location)
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Looks like we're at cross-purposes here with two threads on the same topic... Copy + Name Multiple Files of Same Name
_________________________
We all live in a Yellow Subroutine...

Top
#36450 - 2003-02-14 10:46 PM Re: Not overwrite files (... copy multiple files of same name to one location)
MCA Offline
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.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.057 seconds in which 0.029 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org