Re: rename files in directory
- From: John <John@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 7 Feb 2008 10:10:00 -0800
Thank you Pegasus,
When I run your script I get an error: " Microsoft VBScript runtime error:
Invalid procedure call or argument: 'left' " Any Idea's why? All I changed
was the first line. I changed it to the path that contained to files I wanted
to rename.
v/r
john
"Pegasus (MVP)" wrote:
.
"John" <John@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8B0C55BB-52D6-42BF-96E5-2DB7B4E8EE93@xxxxxxxxxxxxxxxx
Hello, Someone on the windows xp newsgroup said I should post this on the
vb
script group.
I have a directory that list hundreds of files with a name in this format:
"Name of file - 0001.pdf" I would like to create a command that would
switch
the number of the file to the beginning of the file name. ie. "0001 - name
of
file.pdf" This command should do this for each file in the directory. I
figure I should be able to do it with a for command but can not figure out
how to start. Could anyone get me started?
v/r
john
You could use this script:
const strSourceDir = "'D:\Tue'"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name=" & strSourceDir _
& "} Where ResultClass = CIM_DataFile")
For Each objFile In colFiles
p = InStr(objFile.FileName, " - ")
strName = Left(objFile.FileName, p-1) & "."
strNumber = Right(objFile.FileName, 4) & " - "
strNewName = objFile.Drive & objFile.Path _
& strNumber & strName & objFile.extension
errResult = objFile.Rename(strNewName)
Next
Watch for the single+double quotes around strSourceDir
and try the script on a sample folder first!
The script should work well for small folders. For larger
folders a different approach would be more appropriate.
- Follow-Ups:
- Re: rename files in directory
- From: Tom Lavedas
- Re: rename files in directory
- References:
- Re: rename files in directory
- From: Pegasus \(MVP\)
- Re: rename files in directory
- Prev by Date: Re: Can vbscript access System.IO,FileSystemWatcher?
- Next by Date: Re: rename files in directory
- Previous by thread: Re: rename files in directory
- Next by thread: Re: rename files in directory
- Index(es):
Relevant Pages
|