#185796 - 2008-02-28 01:53 PM
Renaming files
|
brewdude6
Hey THIS is FUN
Registered: 2000-10-21
Posts: 280
Loc: Nashville, TN
|
I need do a directory listing of files that has a file name format like this.
I need to take this list of files and rename in this format.
servername_PROD_YYYYMMDD_HHMMSS_fooLOG_0000.csv
The "0" after foolog is the part that is causing me some problems. In the renamed format the series of "0's" is any number up to thousands but I need to pad 0's if it isn't 4 digits.
Also, when I run this against a directory, it will only process one file while deleting the rest of the directory.
Here is what I have so far. Any help would be appreciated:
$path="c:\admin\foo"
$archive="c:\admin\archive"
$date=@DATE
$time=@TIME
$modtime=Join(Split($time,":"),"")
$moddate=Join(Split($date,"/"),"")
$Dir = dirscan($path,1)
For Each $file in $dir
If InStr($file,"-")
Move $path+"\"+$file $archive+"\"+@wksta+"_prod_"+$moddate+"_"+$modtime+"_foolog_0000.csv"
EndIf
Next
_________________________
I could have made a neat retort but didn't, for I was flurried and didn't think of it till I was downstairs. -Mark Twain
|
|
Top
|
|
|
|
#185804 - 2008-02-28 05:03 PM
Re: Renaming files
[Re: brewdude6]
|
brewdude6
Hey THIS is FUN
Registered: 2000-10-21
Posts: 280
Loc: Nashville, TN
|
I abandoned the "move" command temporarily and tried using the rename udf. I think I still have the same problem, but I don't understand why. I get the first file renamed and the rest are ignored.
$path="c:\admin\foo"
$archive="c:\admin\archive"
$date=@DATE
$time=@TIME
$modtime=Join(Split($time,":"),"")
$moddate=Join(Split($date,"/"),"")
$filename=@wksta+"_prod_"+$moddate+"_"+$modtime+"_foolog_0000.csv"
$Dir = dirscan($path,1)
For Each $file in $dir
If InStr($file,"-")
rename($path,$file,$filename)
EndIf
Next
_________________________
I could have made a neat retort but didn't, for I was flurried and didn't think of it till I was downstairs. -Mark Twain
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1334 anonymous users online.
|
|
|