#133572 - 2005-02-10 09:04 PM
Re: Directory list array with exclusion and rename files
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
How about this?
Code:
$folder = "%temp%"
$dir = dirplus($folder,"/a-d /f log")
for each $file in $dir
$file.move($folder + "\file"+$i+".log")
$i = $i+1
next
Will rename all fo the *.log files in the %temp% folder to file#.log
Edited by Bryce (2005-02-10 10:09 PM)
|
|
Top
|
|
|
|
#133574 - 2005-02-11 01:40 AM
Re: Directory list array with exclusion and rename files
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
just want to make sure i am 100% on what you are wanting to do.
You want to rename all *.log files in a folder to "file#.log" # equals a increasing counter. But you dont want to rename "archive.log" is that correct?
While you answer taht, a few pointers that i am spotting that will lead to problems.
(be sure that you got DIRPlus 2.31 (i had a small bug fix)
1.
$folder = "c:\temp" $archive=$folder+"archive.log"
$archive is equal to "c:\temparchive.log" you are missing a "\"
$archive=$folder+"\archive.log"
2.
DirPlus returns an array of FSO objects, so i am unsure how well remfromarray() will handle this.
one method would be to do something like this.
Code:
$folder = "c:\temp" $archive= "archive.log"
$dir = dirplus($folder,"/a-d /f log")
For Each $file in $dir if $file.name <> $archive $file.Move($folder + "\file"+$i+".log") $i = $i+1 endif Next
|
|
Top
|
|
|
|
#133578 - 2005-02-11 06:50 PM
Re: Directory list array with exclusion and rename files
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
eep! LONG LINES!!
The $file.name and $File.Move are FSO object commands/references. The UDF DIRPlus returns an array of FSO objects of the requested files and or folders.
other FSO items.. are.
$file.path ;this is the full path to the file. $file.datelastmodified ;the date of the last change to the file.
there are a lot....
here is a simple example of what DIRPlus is doing (minus directory recursion, and the filter options.)
Code:
$folder = "%temp%"
;this returns the specified Folder's FSO handle $Folder_FSO = CreateObject("Scripting.FileSystemObject").getfolder($folder)
;this will list all subfolders in the root of $folder for each $Subfolder in $Folder_FSO.subfolders ? $SubFolder.name next
;this will list all files on the root of $Folder For each $file in $Folder_FSO.files ? $File.name next
DIRPlus takes those 2 simple steps and expands on them. It gives you the options to do a recursive directory crawl, with some strong filter options built into it. The UDF was built and modeled after a DOS DIR command.
For more information on all what you can do with FSO object.
Bryce
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1607 anonymous users online.
|
|
|