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

  • Home
  • SEARCH
  • 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 8440793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:23:33+00:00 2026-06-10T08:23:33+00:00

I am making a program that automatically backs up files, stores up to a

  • 0

I am making a program that automatically backs up files, stores up to a maximum of five of them, and has an option to restore any of the five files. When the files are backed up, it adds a date and time stamp in the format of YYYYMMDD_HHMMSS_filename.ext. In order to restore the file, it is necessary to first cut out the date stamp.
The method I am currently using to cut the date stamp off of the beginning of the file is as follows.

set VAR=%VAR:~16%
echo %VAR%

The problem being, if the backed up file is called “20120825_140343_file name.txt”, the above method will only return “file,” omitting anything after the space. The spaces in the file names need to be preserved for them to be recognized by the program using them.

tl;dr I need to cut the string 20120825_140343_file name.txt into just “file name.txt”, but my method just returns “file.”

If delimiters or something would help I could separate the date stamp and file name with a different character, I.E. 20120825_140343-file-name.txt

  • 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-06-10T08:23:35+00:00Added an answer on June 10, 2026 at 8:23 am

    Your method, though inelegant and inflexible, should work. This tells me that you are not storing the entire filename in VAR. That is why %var:~16% only results in file, and not file name.txt. I assume that you assign VAR like this somewhere:

    SET VAR=%1
    

    You’ll need to either do this:

    SET VAR=%1 %2
    

    Or insert double-quotes around the file name when you call your batch file, and then set var like this to remove the quotes:

    SET VAR=%~1
    

    That should be enough to get your batch to work.

    ====================================================

    But, to answer the question you actually asked, I’ll show you a method of extracting “file name.txt” from var that will work even if there are more or even less than 16 prefix characters.

    Use the for /f statement, specify the 3rd token, with underscores as a delimiter. Here is a self-contained example. (To run from the command-line, change %%x to %x.

    SET VAR=20120825_140343_file name.txt
    for /f "tokens=3 delims=_" %%x in ("%VAR%") do set VAR=%%x
    ECHO %VAR%
    

    Just remember, this solution will NOT fix your problem if you do not fix your code to assure your VAR variable has the entire filename in it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a program that reads and stores data from Windows EventLog files
I'm making a program that will move around quite huge sets of files, sometimes
I'm making a program that will have a widget that has to be fixed
I'm making a program that allows you to add any class file that extends
I am making a program that stores data in a 2D array. I would
So I am making a program that has a script Set of Steps to
I'm making a very simple WCF (C#, .NET 4.0) licensing program that automatically emails
I am making a program that automates the seperation of a csv file. We
I am making a program that graphs a line based on data inputted by
I am currently making a program that will send an email if the date

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.