Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6330939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:57:48+00:00 2026-05-24T17:57:48+00:00

I need to either write a batch file or a vbscript that will rename

  • 0

I need to either write a batch file or a vbscript that will rename files. I need to keep everything in the file name up to the second “.” but delete what comes after the second dot.

This is a sample of what the file names look like:

nnnnnnnnnnnnnnnn.xxxxxxxx.dddddddddd.pdf 
  • n= 16 numbers 0-9
  • x= date in this format ex:02232008
  • d= 10 numbers 0-9, this is the part of the file name that I want to delete.

I need the d’s from the sample above to be deleted but keep the rest of the file name the same. I need to be able to run this batch file on a folder that contains about 3,000 pdf files. It can either be put right back into the same folder or outputted into a different folder.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:57:48+00:00Added an answer on May 24, 2026 at 5:57 pm

    In VBScript, you can use something like

    ' the file paths. hardcoded, but you could alternatively collect these via command line parameters
    Const IN_PATH = "path\to\directory"
    Const OUT_PATH = "path\to\another\directory"
    
    ' check that the directories exist. you could create them instead, but here
    ' it just throws an error as that's easier
    dim fso: set fso = CreateObject("Scripting.FileSystemObject")
    if not fso.FolderExists(IN_PATH) then
        err.raise 1,, "Path '" & IN_PATH & "' not found"
    end if
    if not fso.FolderExists(OUT_PATH) then
        err.raise 1,, "Path '" & OUT_PATH & "' not found"
    end if
    
    dim infolder: set infolder = fso.GetFolder(IN_PATH)
    dim file
    for each file in infolder.files
        dim name: name = file.name
        dim parts: parts = split(name, ".")
        ' we're expecting a file format of a.b.c.pdf
        ' so we should have 4 elements in the array (zero-indexed, highest bound is 3)
        if UBound(parts) = 3 then
            ' rebuild the name with the 0th, 1st and 3rd elements
            dim newname: newname = parts(0) & "." & parts(1) & "." & parts(3)
            ' use the move() method to effect the rename
            file.move fso.buildpath(OUT_PATH, newname)
        else
            ' log the fact that there's an erroneous file name
            WScript.Echo "Unexpected file format: '" & name & "'"
        end if
    next 'file
    

    You would run it in a batch file thus, redirecting output to a log file

    cscript rename-script.vbs > logfile.txt
    

    This assumes that you can simply rely on the period to delimit the parts of the file name rather than the specifics of the format of the delimited parts.


    To rearrange the date, which I think is in the parts(1) array element, you can simply extract each bit of the string because it’s in a specific format:

    'date in format mmddyyyy
    dim month_, day_, year_, date_
    month_ = left(parts(1), 2)
    day_ = mid(parts(1), 3, 2)
    year_ = right(parts(1), 4)
    date_ = year_ & month_ & day_ ' now yyyymmdd
    

    so when rebuilding the filename, you can replace parts(1) with the new formatted date

    dim newname: newname = parts(0) & "." & date_ & "." & parts(3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to either find a file in which the version is encoded or
Greetings, I need a way (either via C# or in a .bat file) to
Need to an expression that returns only things with an I followed by either
Please forgive my attempts at necromancy, but I actually need to write some code
I need to write a UDF that would try to cast a varchar to
I'm trying to write a method that will return a Hibernate object based on
I have a Java server process that I normally run in either Windows batch
I am using Zend Framework(MVC part of it), and need to either redirect user
Need a function that takes a character as a parameter and returns true if
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.