Page 1 of 1 1
Topic Options
#36419 - 2003-02-12 05:26 PM Copy + Name Multiple Files Of Same Name
Mike Duhwald Offline
Fresh Scripter

Registered: 2003-01-13
Posts: 40
Hi,
I want to save all Files with the name 'test.html' on my client. Unfortunaly there are several files with the same name on the pc.

So I want to save these files with 'test1.html', 'test2.html' and so on.

If I run the script again and a file with the name 'test1.html' or 'test2.html' etc. already exist, the script should carry on with 'test3.html', ...

I use this code provided by MCA
code:
  
$search_key="c:\*.pst"
$server="x:\outlook" ; <== destination directory on your server.
; ; <== it can be also something like "\\server\share"
;
IF (Exist("%temp%\kixtart.tmp") = 1)
DEL %temp%\kixtart.tmp
ENDIF
SHELL "%comspec% /e:1024 /c dir "+$search_key+" /a /b /s >%temp%\kixtart.tmp"
SHELL "%comspec% /e:1024 /c echo -end.of.list- >>%temp%\kixtart.tmp"
IF (Exist ("%temp%\kixtart.tmp") = 1)
IF Open(1,"%temp%\kixtart.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
? Substr("$count"+" ",1,4)+" "+$result+" ("+GetFileSize($result)+" bytes "+GetFileTime($result)+")"
IF Open(2, $result)
ENDIF
; - your actions on this file
GOSUB additional_actions
IF Close(2)
ENDIF
ENDIF
LOOP
IF Close(1)
ENDIF
IF ($count <> 0)
? "Informative KIX: "+$count+" files found with key '"+$search_key+"'."
ELSE
? "Warning KIX: no files found with key '"+$search_key+"'."
ENDIF
ENDIF
DEL %temp%\kixtart.tmp
EXIT
:additional_actions
IF (Substr($server,Len($server),1) = "\")
$server=Substr($server,1,Len($server)-1)
ENDIF
IF ($count > 1)
$destination=$server+"\"+@userid+"_"+$count+".pst"
ELSE
$destination=$server+"\"+@userid+".pst"
ENDIF
? "Info: copy '"+Lcase($result)+"' ("+GetFileSize($result)+" bytes)"
COPY $result $destination /h
IF (@error <> 0)
? "Warning: error @error (@serror)"
ENDIF
RETURN

In this case the files will be overwriten if existent. How must I modify the script to fit my task?

Regards
Mike

Top
#36420 - 2003-02-12 10:03 PM Re: Copy + Name Multiple Files Of Same Name
Mike Duhwald Offline
Fresh Scripter

Registered: 2003-01-13
Posts: 40
Hi,
can anyone help? I don't know how to modify it by myself!

Regards
Mike

Top
#36421 - 2003-02-12 10:32 PM Re: Copy + Name Multiple Files Of Same Name
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You will need to enumerate the existing test*.html files, find the biggest number, then use that number to increment the numbers on the new files. Reconstruct a new file with the number, continue copying.

A helpful UDF is DIRPLUS().

[ 15. February 2003, 16:02: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#36422 - 2003-02-13 08:59 AM Re: Copy + Name Multiple Files Of Same Name
Mike Duhwald Offline
Fresh Scripter

Registered: 2003-01-13
Posts: 40
Thank you for your contribution. Due the fact that I´m not familiar with KIX I don't know how to ralize it...

Any further help appreciated

Regards
Mike

Top
#36423 - 2003-02-13 02:22 PM Re: Copy + Name Multiple Files Of Same Name
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Maybe GUICopy() can help you. It has a switch for copying a file with a new name if the old already exists. It does have some OS requirements, so follow the link for more details.
Top
#36424 - 2003-02-13 03:06 PM Re: Copy + Name Multiple Files Of Same Name
Mike Duhwald Offline
Fresh Scripter

Registered: 2003-01-13
Posts: 40
Hello Chris,
sorry, but I'm using NT 4.0 and the shell32.dll is not the version GUICOPY needs and it is not going through subdirectories...

But thanks
Mike

Top
#36425 - 2003-02-14 07:50 PM Re: Copy + Name Multiple Files Of Same Name
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

We have made some changes to it.
We are searching in this case for all test.html on your C-drive.
We backup it to a share folder on your server. In this situation we are
calling it x:\backup, which can be shared by all users.

Also we introduce a $destination_prefix variable at the begin of this
script. In our situation we have add @userid_ as prefix for each
file.
You can change it to $destination_prefix=$server+"\", when you aren't
sharing the server location with other users.

code:
 $search_key="c:\test.html"
$server="x:\backup" ; <== destination directory on your server.
; ; <== it can be also something like "\\server\share"
;
IF (Substr($server,Len($server),1) = "\")
$server=Substr($server,1,Len($server)-1)
ENDIF
$destination_prefix=$server+"\"+@userid+"_"
;
IF (Exist("%temp%\kixtart.tmp") = 1)
DEL %temp%\kixtart.tmp
ENDIF
SHELL "%comspec% /e:1024 /c dir "+$search_key+" /a /b /s >%temp%\kixtart.tmp"
SHELL "%comspec% /e:1024 /c echo -end.of.list- >>%temp%\kixtart.tmp"
IF (Exist ("%temp%\kixtart.tmp") = 1)
IF Open(1,"%temp%\kixtart.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
? Substr("$count"+" ",1,4)+" "+$result+" ("+GetFileSize($result)+" bytes "+GetFileTime($result)+")"
IF Open(2, $result)
ENDIF
; - your actions on this file
GOSUB additional_actions
IF Close(2)
ENDIF
ENDIF
LOOP
IF Close(1)
ENDIF
IF ($count <> 0)
? "Informative KIX: "+$count+" files found with key '"+$search_key+"'."
ELSE
? "Warning KIX: no files found with key '"+$search_key+"'."
ENDIF
ENDIF
DEL %temp%\kixtart.tmp
EXIT
:additional_actions
IF ($count > 1)
$destination=$destination_prefix+"test_"+$count+".html"
ELSE
$destination=$destination_prefix+"test.html"
ENDIF
? "Info: copy '"+Lcase($result)+"' ("+GetFileSize($result)+" bytes)"
COPY $result $destination /h
IF (@error <> 0)
? "Warning: error @error (@serror)"
ENDIF
RETURN

Please try is and return the results to this board.
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
#36426 - 2003-02-14 10:49 PM Re: Copy + Name Multiple Files Of Same Name
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Above version works for all kixtart releases 3.6x and 4.x
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
#36427 - 2003-02-15 10:14 AM Re: Copy + Name Multiple Files Of Same Name
Mike Duhwald Offline
Fresh Scripter

Registered: 2003-01-13
Posts: 40
Hello MCA,
thank you for your help. The script works for me but sadly doesn't fit my task. The main problem I have ist the following:

1. I want to save all client test.html files in a directory named after the workstation the script was started. If there are more than one they should be named test1.html, test2.html .. Thes files can be overwritten if the script is started a second time

2. All test.html files from each client the script was started should be backuped in the main backupdirectory. The files should not be overwritten and named test1.html, test2.html... test99.html...

I tried it by my own..but with no success [Frown]

Regards
Mike

Top
#36428 - 2003-02-15 04:06 PM Re: Copy + Name Multiple Files Of Same Name
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Start be creating a flow-chart. Start with the most general description. Then, etch out each of the general descriptions with more detail. Finally, describe the detailed descriptions with pseudo-code.

Alternatively, rework the problem in order to create a simpler solution or break up the problem into smaller sub-problems.

[ 16. February 2003, 16:38: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

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 1386 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.049 seconds in which 0.021 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