Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ ASP and VBScript _ Command To Rename Files In Folder

Posted by: bakersburg9 Jul 22 2019, 10:48 AM

Is there a command / script to rename all files in a folder ?

Say my files were like:

Smith, John 2019-17-18
Brown, Ray 2019-17-18

and I wanted to change them, say, to

Smith_John_July_18
Brown_Ray_July_18

Or would it be easier or just as fast to write a macro to do basically the same thing ?

Thanks in advance,
Steve

Posted by: theDBguy Jul 22 2019, 10:50 AM

Hi Steve. Not sure about a command but you can always use a script to do it. For example, you could try using batch file, command script, or PowerShell script.

Posted by: bakersburg9 Jul 22 2019, 11:52 AM

Thanks! Do you have an example of a batch file ? I could tweak it

thanks for chiming in !

Steve

Posted by: theDBguy Jul 22 2019, 12:02 PM

Hi Steve. I don't, so I'll just send you to https://www.computerhope.com/issues/ch000987.htm for an example you might be able to modify and apply to your needs. Good luck!

Posted by: bakersburg9 Jul 22 2019, 12:15 PM

DBguy from San Diego - THANKS !!!!! cool.gif

Steve

Posted by: theDBguy Jul 22 2019, 12:18 PM

Don't mention it. Good luck!

Posted by: ADezii Jul 22 2019, 12:32 PM

Here is a little Demo that I created for you to hopefully illustrate how you can Rename all Files in a Folder. The following Code will:

  1. Rename all Files in the C:\Test Folder to BaseFileName & Suffix & Extension.
  2. Define your own Folder and Suffix in the USER DEFINED SECTION.
  3. Code Definition:
    CODE
    Dim strFile As String
    Dim strBaseName As String
    Dim strExt As String

    '****** USER DEFINED SECTION ******
    Const conFOLDER = "C:\Test"
    Const conSUFFIX = "_July_18"
    '**********************************

    strFile = Dir$(conFOLDER & "\*.*")

    Do While strFile <> ""
      strBaseName = Left$(strFile, InStrRev(strFile, ".") - 1)
        Name conFOLDER & "\" & strFile As conFOLDER & "\" & _
             Replace(strFile, strBaseName, strBaseName & conSUFFIX)
          strFile = Dir
    Loop

    Close #1
  4. Files in C:\Test Folder prior to Code Execution:
    CODE
    Five.pdf
    Four.mdb
    My Final Resume_July_18.docx
    One.JPG
    Seven.accdb
    Six.mdb
    Three.zip
    Two.txt
  5. Files in C:\Test Folder after Code Execution:
    CODE
    Five_July_18.pdf
    Four_July_18.mdb
    My Final Resume_July_18.docx
    One_July_18.JPG
    Seven_July_18.accdb
    Six_July_18.mdb
    Three_July_18.zip
    Two_July_18.txt
  6. Hopefully, this is what you are looking for.


Posted by: bakersburg9 Jul 22 2019, 12:36 PM

Adezii,

I'll get to work on that ASAP - thanks !!!!! cool.gif

question: the Close#1 - that's code, or did you mean to comment that line out - I don't follow what it's doing if it is supposed to be code, which I'm guessing it is - never seen anything like that...

thanks again!

Steve

Posted by: ADezii Jul 22 2019, 01:38 PM

Close #1, my apologies/my mistake. You can remove it.