Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: VB script: Rename all files in a folder to a specified prefix

29 Jan 2015   #1
moonsie

64 bit
 
 
VB script: Rename all files in a folder to a specified prefix

Hi, I'm trying to find help in entering paths and prefix's in my vb script.
I am of course a newbie to visual basic and don't know where to enter the path and wording for prefix.
Any help would be most appreciated.
Rich




Attached Thumbnails
VB script: Rename all files in a folder to a specified prefix-rename1.jpg   VB script: Rename all files in a folder to a specified prefix-rename2.jpg  
My System SpecsSystem Spec
.
29 Jan 2015   #2
Tookeri

Windows 7 Pro 32
 
 

You're not supposed to enter those in the script, but instead set as parameters to the file when you execute it. Example:

rename.vbs c:\somepath somePrefix

use " around the path if it contains spaces, example "c:\some folder"
My System SpecsSystem Spec
29 Jan 2015   #3
moonsie

64 bit
 
 

Hi Tookeri, Thank you for responding.
Where do you place the rename.vbs c:\somepath someprefix ? I assume the top of the page.
My System SpecsSystem Spec
.

29 Jan 2015   #4
Tookeri

Windows 7 Pro 32
 
 

No. From a command window, or from the Start Orb in the text box "Search programs and files"

The script is designed that way so you never have to modify the code to be able to execute it for different paths and suffixes.
My System SpecsSystem Spec
29 Jan 2015   #5
moonsie

64 bit
 
 

Tookeri, I receive this alert when I run the script.

The code: RenameFiles.vbs "c:\Users\Richards" sp_train 01.jpg
Where I placed the code:
WScript.Echo "RenameFiles.vbs requires 2 parameters:" &_
vbcrlf & "1) Folder Path (or . for current folder)" &_
vbcrlf & "2) File Prefix" &_
vbcrlf & "3) Confirm each file? True/*False* (optional)"
WScript.Quit
RenameFiles.vbs "c:\Users\Richards" sp_train 01.jpg


Attached Images
VB script: Rename all files in a folder to a specified prefix-windows-script-host.jpg 
My System SpecsSystem Spec
29 Jan 2015   #6
Tookeri

Windows 7 Pro 32
 
 

Not sure I understand what you did when you "placed the code". You shouldn't add anything to or in the code.
If this was copied from the code then delete the bold line:

WScript.Echo "RenameFiles.vbs requires 2 parameters:" &_
vbcrlf & "1) Folder Path (or . for current folder)" &_
vbcrlf & "2) File Prefix" &_
vbcrlf & "3) Confirm each file? True/*False* (optional)"
WScript.Quit
RenameFiles.vbs "c:\Users\Richards" sp_train 01.jpg
My System SpecsSystem Spec
29 Jan 2015   #7
moonsie

64 bit
 
 

Hi Tookeri,
I really feel dense.
I removed all the code I added to the original script and ran it in an Admin command prompt and received these errors.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Windows\System32>Option Explicit
'Option' is not recognized as an internal or external command,
operable program or batch file.

C:\Windows\System32>Dim oCmd, oFolder, oFSO, oFileList, oFile
'Dim' is not recognized as an internal or external command,
operable program or batch file.

C:\Windows\System32>Dim sRenamePath, sRenamePrefix, sFileExtension, sConfirmRena
me
'Dim' is not recognized as an internal or external command,
operable program or batch file.

C:\Windows\System32>Dim iFileCount, iFileIndex
'Dim' is not recognized as an internal or external command,
operable program or batch file.

C:\Windows\System32>Dim bConfirmEach
'Dim' is not recognized as an internal or external command,
operable program or batch file.

Thanks for your patience.
My System SpecsSystem Spec
29 Jan 2015   #8
Tookeri

Windows 7 Pro 32
 
 

Not sure why that's failing. As a test try in the command prompt to only type rename.vbs without parameters. That should print the information about how the parameters work.

Also test from Windows Start Search to see if that makes a difference.

And check if the script came with any specific instructions on how to execute it.
My System SpecsSystem Spec
30 Jan 2015   #9
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by moonsie View Post
I removed all the code I added to the original script and ran it in an Admin command prompt and received these errors.
[...]
C:\Windows\System32>Option Explicit
'Option' is not recognized as an internal or external command,
operable program or batch file.

[etc. ...]
Some confusion needs clearing up.

WScript.exe and CScript.exe are the interpreters for VBScript (and JScript alike). The only scripting language that Cmd.exe recognises is Batch and solely Batch. The command prompt wants nothing to do with other languages. It does not know what to do with other languages.

So don't go pasting lines of VBScript into the command prompt and expect no errors will be returned.
My System SpecsSystem Spec
30 Jan 2015   #10
jimbo45

Linux CENTOS 7 / various Windows OS'es and servers
 
 

Hi there

If you can download a Live LINUX CD then it's simple (beware of spaces / whitespace though in file names).
This command will add PRE_ to the filenames for example.

ls | xargs -I {} mv {} PRE_{}

Here's another command script (Linux) -- it will find say all html files and add prefix_ in front of their names
for f in $(find . -name '*.html'); do mv "$f" "$(dirname "$f")/prefix_$(basename "$f")"; done

With PERL it's also astonishingly simple

perl -e 'rename $_, "PRE_$_" for <*>

I think you can install perl on windows

Installing Perl on Windows (32 and 64 bit) - learn.perl.org

Forget vbscript it's JUNK, CLUNKY and quite difficult to get anything to work properly.

Another good teaching code language is PYTHON -- being taught in UK schools now too.

For Windows you can download

https://www.python.org/downloads/windows/

Very simple, powerful and worth having a look at.

Cheers
jimbo
My System SpecsSystem Spec
Reply

 VB script: Rename all files in a folder to a specified prefix




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Script to Auto Rename Multiple Files in Windows Explorer
Is there a way to automate the renaming of multiple files in windows explorer which will also add the Julian date at the beginning of each file name. I have a sign-in roster for my employees at work to digitally sign each day when the report to work and again before the depart. I have been...
General Discussion
How to script a daily copy of files w/dt being name of archive folder
Hello, I need to figure out a Windows 7 script to copy/archive files which are located in a specific folder. It needs to copy daily to an archive folder, with the script creating the archive folder as MM-DD-YY (being that day's date that is being archived) before it archives the files to that...
General Discussion
Program to monitor folder and rename files?
Hi All, i'm looking for a way to auto rename files with a pre defined prefix and consecutive numbers when they are moved into a folder. I have tried a program called personal rename, I can get the rename function to work but the folder monitoring is giving me issues, not sure if it doesn't work the...
Software
GROD in only one folder, can't delete/move/rename files in it
Hello guys, I've read this forum so many times and I'm usually good at finding solutions on the web by browsing forums and articles but now ...can't fix this :( I hope someone will be able to help me I have a acer aspire 7750G-6634 laptop, 8gb of ram, 2 HDs, i5, windows 7 home (the one that...
General Discussion
How do I rename this Folder?
It's under Local Disc C -> Users it's says Public and then "Cam" which I want to change to my name of the laptop. I got my laptop fixed a couple of weeks ago, and the technician restored it and i guess renamed all the important files "cam". I've changed my username in Control Panel but that...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 07:14.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App