Picture 001.jpg
Picture 002.jpg
etc..
And I want them to end up like this:
Picture001.jpg
Picture002.jpg
etc..
All I need is a script I can run from the command line and use a
directory as the argument and it will rename all the files in the
directory. Somthing like this:
c:\windows\rename.vbs c:\my documents\my pictures\2003-9-3
Can anyone help me out with this?
TIA
Folder Object
http://msdn.microsoft.com/library/en-us/script56/html/jsobjfolder.asp
Files Collection
http://msdn.microsoft.com/library/en-us/script56/html/jscolfiles.asp
Name Property
http://msdn.microsoft.com/library/en-us/script56/html/jsproname.asp
Replace Function
http://msdn.microsoft.com/library/en-us/script56/html/vsfctreplace.asp
Download Windows Script Documentation
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
--
Steve
When choosing between two evils, I always like to try the one I've never
tried before. -Mae West
This will take me a bit, so give me a few :)
Mythran
Save the text below to a vbs file:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''
Option Explicit
Dim StdIn: Set StdIn = WScript.StdIn
Dim StdOut: Set StdOut = WScript.StdOut
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim FilesRenamed: FilesRenamed = 0
Main
Sub Main
Dim FolderPath
FolderPath = WScript.Arguments(0)
Dim CurrentFolder
Set CurrentFolder = fso.GetFolder(FolderPath)
ProcessFolder CurrentFolder
StdOut.WriteLine FilesRenamed & " Files renamed."
End Sub
Sub ProcessFolder (ByVal Folder)
Dim Files: Set Files = Folder.Files
Dim File
For Each File In Files
If InStr(1,File.Name," ") > 0 Then
File.Move Replace(File.Path," ","")
FilesRenamed = FilesRenamed + 1
End If
Next
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
Useage:
cscript <filename>.vbs <folderpath>
eg. cscript rename.vbs c:\myfolder
Seems cool on 2000 so should be OK for XP.
Jason
"Mythran" <kip_p...@hotmail.com> wrote in message
news:eAYMmJjc...@TK2MSFTNGP12.phx.gbl...
I tried them both but am using this one for now. One problem, it
has a problem with the path. I think it has a problem with paths
with spaces (c:\documents and settings\...)
when I move the folder to c:\2003-09-02 and use it that way it works
perfect.
Is there a way you can put the main path in the script so it
automatically know to look in:
C:\Documents and Settings\Warren Bell\My Documents\My Pictures
and then I can just specify the directory form there?
So instead of:
cscript rename.vbs C:\Documents and Settings\Warren Bell\My
Documents\My Pictures\2003-09-02
for the command line, I would use:
cscript rename.vbs 2003-09-02
Thanks again!
If you want to put the path in the script just add the path (minus the final
folder if you are going to pass it) in the FolderPath variable i.e :
To rename files in C:\Documents and Settings\Warren Bell\My Documents\My
Pictures\2003-09-02 the first two lines in sub main become
Dim FolderPath
FolderPath = "C:\Docume~1\Warren~1\MyDocu~1\MyPict~1\" &
WScript.Arguments(0)
which would be run using:
cscript rename.vbs 2003-09-02
The ~1 is just the dos naming format for folder names with spaces (shorten
any name longer than eight letters to six letters while removing spaces and
adding the tilde/number).
Good luck
Jason
"Warren Bell" <wjb...@belletc.net> wrote in message
news:eDDB8Wnc...@TK2MSFTNGP10.phx.gbl...
Thanks, works perfect.
One other thing, if you have time...
It would be nice if I could double click on the vbs file and have it
pop up a form field that I can enter in the argument, like
2003-09-02. Then hit OK and it would preform the action.
If you have time I would appreciate it, if not you've helped me out
hugely already, thanks.
Full source again, just incase.....
Just dbl click and you will get an inputform for the folder name arg.
By the way - just check the FolderPath variable - I think this was it.
Jason
----------------------------------------------------------------------------
-
Option Explicit
Dim StdIn: Set StdIn = WScript.StdIn
Dim StdOut: Set StdOut = WScript.StdOut
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim FilesRenamed: FilesRenamed = 0
Main
Sub Main
Dim FolderPath
Dim FolderName
FolderName = InputBox("Enter Folder Name")
FolderPath = "C:\Docume~1\Warren~1\MyDocu~1\MyPict~1\" & FolderName
Dim CurrentFolder
Set CurrentFolder = fso.GetFolder(FolderPath)
ProcessFolder CurrentFolder
msgbox FilesRenamed & " Files renamed."
End Sub
Sub ProcessFolder (ByVal Folder)
Dim Files: Set Files = Folder.Files
Dim File
For Each File In Files
If InStr(1,File.Name," ") > 0 Then
File.Move Replace(File.Path," ","")
FilesRenamed = FilesRenamed + 1
End If
Next
End Sub
--------------------------------------------------------
"Warren Bell" <wjb...@belletc.net> wrote in message
news:OKDF85uc...@TK2MSFTNGP09.phx.gbl...
Did you try putting the path in quotes ?
cscript rename.vbs "C:\my path with spaces"
TDM
"Warren Bell" <wjb...@belletc.net> wrote in message
news:eDDB8Wnc...@TK2MSFTNGP10.phx.gbl...