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

Page 1 of 2 12 LastLast

  1. Posts : 8
    64 bit
       #1

    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 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 Computer


  2. Posts : 1,049
    Windows 7 Pro 32
       #2

    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 Computer


  3. Posts : 8
    64 bit
    Thread Starter
       #3

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


  4. Posts : 1,049
    Windows 7 Pro 32
       #4

    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 Computer


  5. Posts : 8
    64 bit
    Thread Starter
       #5

    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 Thumbnails Attached Thumbnails VB script: Rename all files in a folder to a specified prefix-windows-script-host.jpg  
      My Computer


  6. Posts : 1,049
    Windows 7 Pro 32
       #6

    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 Computer


  7. Posts : 8
    64 bit
    Thread Starter
       #7

    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 Computer


  8. Posts : 1,049
    Windows 7 Pro 32
       #8

    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 Computer


  9. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #9

    moonsie said:
    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 Computer


  10. Posts : 5,941
    Linux CENTOS 7 / various Windows OS'es and servers
       #10

    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
    Last edited by jimbo45; 30 Jan 2015 at 04:27.
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About 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 05:31.
Find Us