#175219 - 2007-04-04 07:52 PM
rename files script
|
booey
Getting the hang of it
Registered: 2005-07-25
Posts: 76
Loc: USA
|
I have the following script to rename the files in a directory and add a 1,2,3, etc to the end of the file. I want the number to be in the format of filenamedate-1.tif, filenamedate-2.tif, etc. When I run the script, the first file adds a hyphen at the end of the filename with no number after it, such as filenamedate-.tif.
Is there a way to start with the -1 on the first file? If not, can I prevent the "-" from appearing at the end of the first filename?
Here's what I have so far:
$folder = "U:\test\"
$dir = dirplus($folder,"/a-d /f tif")
$date = Trim(Join(Split(@DATE,'/'),'-'))
For Each $file In $dir
$file.Move($folder + "AND" + $date + "-" + $i + ".tif")
? @SERROR
$1 = 1
Next
|
|
Top
|
|
|
|
#175222 - 2007-04-04 08:30 PM
Re: rename files script
[Re: booey]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I do net get your code totally but I think you forget to give an initial value to $i and afterwards you forget to add 1 to $i in every loop you make something like:
$folder = "U:\test\"
$Dir = dirplus($folder,"/a-d /f tif")
$i = 1
$date = Trim(Join(Split(@DATE,'/'),'-'))
For Each $file In $Dir
$file.Move($folder + "AND" + $date + "-" + $i + ".tif")
? @SERROR
$i = $i + 1
Next
|
|
Top
|
|
|
|
#175223 - 2007-04-04 09:24 PM
Re: rename files script
[Re: Witto]
|
booey
Getting the hang of it
Registered: 2005-07-25
Posts: 76
Loc: USA
|
You're right. I was cleaning up my code a little when posting and deleted the wrong line. You're suggestion is what I have, but I still have the same issue.
|
|
Top
|
|
|
|
#175226 - 2007-04-04 10:10 PM
Re: rename files script
[Re: booey]
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
For clarity, please post your current code.
|
|
Top
|
|
|
|
#175227 - 2007-04-04 10:18 PM
Re: rename files script
[Re: Howard Bullock]
|
booey
Getting the hang of it
Registered: 2005-07-25
Posts: 76
Loc: USA
|
Sorry for the confusion.
$folder = "U:\test"
$dir = dirplus($folder,"/a-d /f tif")
$date = Trim(Join(Split(@DATE,'/'),'-'))
For Each $file In $dir
$file.Move($folder + "\AND" + $date + "-" + $i + ".tif")
? @SERROR
$i = $i+1
Next
|
|
Top
|
|
|
|
#175228 - 2007-04-04 10:26 PM
Re: rename files script
[Re: booey]
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You are not initializing the variable "$i" before its first use.
|
|
Top
|
|
|
|
#175229 - 2007-04-04 10:39 PM
Re: rename files script
[Re: Howard Bullock]
|
booey
Getting the hang of it
Registered: 2005-07-25
Posts: 76
Loc: USA
|
What do you mean by "initialize"? Are you talking about doing: "Dim $i" at the top of the script
|
|
Top
|
|
|
|
#175234 - 2007-04-04 11:32 PM
Re: rename files script
[Re: Lonkero]
|
booey
Getting the hang of it
Registered: 2005-07-25
Posts: 76
Loc: USA
|
That worked. Thanks everyone for the help.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 978 anonymous users online.
|
|
|