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

Page 2 of 2 FirstFirst 12

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

    Suggesting different scripting languages are we now, Jimbo?

    In that case, the following Command Prompt command appends the string "PRE_" to each filename in the current directory.
    Code:
    for %I in (*) do ren "%I" "PRE_%~nxI"

    And even easier to accomplish in Windows PowerShell,
    Code:
    gci | ren -new {"PRE_$_"}

    Though, I think Moonsie is more looking forward to fixing his VBScript, rather than reading all about how VBScript is such a bad language compared to blah and blah.


    jimbo45 said:
    Another good teaching code language is PYTHON
    However, I highly recommend this language^
      My Computer


  2. Posts : 2
    Windows 8.1 64-bit
       #12

    The script accepts 2 (optionally 3) parameters.

    The command you entered (RenameFiles.vbs "c:\Users\Richards" sp_train 01.jpg) would be interpreted as 3 parameters, but it doesn't know how to handle the 3rd (01.jpg). It should be 1 or true if you want to prompt for each file, but any non-zero number should work.

    Warning: you might not actually want to run this command. I'm not sure it would succeed, but if it does, it will rename the user hive of your registry (ntuser.dat).

    If you just want to rename the files without prompting, you would want to enter (at the command prompt, see attached image and make sure you are in the directory in which renamefiles.vbs is located):

    RenameFiles.vbs "c:\Users\Richards" sp_train

    Keep in mind that this script doesn't care about file extensions. This is going to rename every file with any extension "sp_train" followed by _ and a number followed by the original extension. For example: "sp_train_01.jpg".

    If you're just trying to rename some files for yourself occaisionally, you might be better off using a tool like 1-4a Rename. It has a GUI and advanced renaming options.
    Attached Thumbnails Attached Thumbnails VB script: Rename all files in a folder to a specified prefix-untitled.png  
    Last edited by chadteck; 30 Jan 2015 at 13:25. Reason: Added warning and attachment.
      My Computer


 
Page 2 of 2 FirstFirst 12

  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 21:34.
Find Us