Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

aff a prefix  to all file in a folder

Posted on 2014-01-26
6
Medium Priority
?
531 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 58

Assisted Solution

by:Bill Prew
Bill Prew earned 600 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 1400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 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