Solved

aff a prefix  to all file in a folder

Posted on 2014-01-26
6
499 Views
Last Modified: 2014-01-28
Dear all,
I need to add a given prefix to all files in a specific folder.
bypassing the prefix to .bat file that execute the vbscript...
thanks in advance.
0
Comment
Question by:ethar1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:Rabih
ID: 39811335
you can download the Bulk Rename Utility. Easy to use and free.


http://www.bulkrenameutility.co.uk/Download.php

it has a lot of options such as renaming, removing extensions, adding a prefix....... all can be applied to a mass number of files.

regards
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39811351
Not sure what you mean by: bypassing the prefix to .bat file that execute the vbscript...

Try this:
  Dim oFS, sDir, oFile, sPrefix
  Set oFS = CreateObject("Scripting.FileSystemObject")

  sDir = "C:\Demo" ' <<<Change to match your folder
  sPrefix = "YourPrefix" ' <<<Change to match your prefix

  For Each oFile In oFS.GetFolder(sDir).Files
     oFile.Name = sPrefix & oFile.Name
  Next

Open in new window

0
 

Author Comment

by:ethar1
ID: 39811872
Thanks for reply,
@ MacroShadow , can I pass the prefix through input box?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 55

Assisted Solution

by:Bill Prew
Bill Prew earned 150 total points
ID: 39811876
I'm interpretting that you want to pass the prefix in as a command line parm, in which case do this in the BAT script:

cscript //nologo yourscript.vbs "c:\temp" "myprefix_"

And access those parms like this in VBS:

' Check for folder name and prefix in command line parms
Set oArgs = WScript.Arguments
If oArgs.Count < 2 Then
    Wscript.Echo "Please specify both a folder name, and a file prefix for renaming."
    Wscript.Quit
End If

' Fetch parms into local variables
sBaseDir = oArgs(0)
sPrefix = oArgs(1)

' Access the folder
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sBaseDir)

' Process all files in the folder
For Each oFile In oFolder.Files
   ' If we haven't already renamed before, then do the rename now
   If LCase(Left(oFile.Name, Len(sPrefix))) <> LCase(sPrefix) Then
      oFile.Name = sPrefix & oFile.Name
   End If
Next

Open in new window

~bp
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 350 total points
ID: 39811920
Sure.
    Dim oFS As Object, oFile As Object
    Dim strDir As String, strPrefix As String

    Set oFS = CreateObject("Scripting.FileSystemObject")

    strDir = "C:\Demo"          ' <<<Change to match your folder
    strPrefix = InputBox("Enter your prefix.", "Prompt")   ' <<<Change to match your prefix

    If Len(strPrefix) > 0 Then
        For Each oFile In oFS.GetFolder(strDir).Files
            oFile.Name = strPrefix & oFile.Name
        Next
    Else
        MsgBox ("No prefix was entered.")
    End If

Open in new window

0
 

Author Closing Comment

by:ethar1
ID: 39817064
thanks guys
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question