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 8834075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:55:49+00:00 2026-06-14T08:55:49+00:00

Note: There is no need to use batch per say, but I am just

  • 0

Note: There is no need to use batch per say, but I am just familiar with batch, Powershell would be better I imagine, so if there are easier solutions for this problem in powershell, please shout!

I have the arduous task of testing our DR backups for all our clients, that is, mounting ShadowProtect Snapshots latest incremental, writing and reading a file, them unmounting the image. The actual ShadowProtect part of batch is fairly simple but I would like to design a batch that can automate this.

Essentially my question is:

How in a batch file can I firstly, enumerate files in a folder, and then place a specific part of a given filename into a variable?

Reason being ShadowProtect incrementals have a naming convention such like:

SERVERNAME_DRIVELETTER_b00X_i000x           - whereby b = base image, i = incremental number

I need to mount the latest incremental image, therefore need to parse the folder and find the latest incremental image, based on the number following the i in the filename.

Is this possible in batch?

Thanks!

  • 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-14T08:55:50+00:00Added an answer on June 14, 2026 at 8:55 am

    Something like this should work:

    @echo off
    
    setlocal EnableDelayedExpansion
    
    for /f "delims=_ tokens=1-4" %%f in ('dir /b *_*_*_*') do (
      set servername=%%f
      set driveletter=%%g
      set base_image=%%h
      set increment=%%i
    )
    
    echo !servername!
    echo !driveletter!
    echo !base_image!
    echo !increment!
    
    endlocal
    

    If you have several matching files and want to do something with all of them, you need to put the processing code inside the loop.

    Edit:

    • for /f: process either a file or the output of a command enclosed in single quotes
    • delims=_: fields in the processed content are separated by underscores
    • tokens=1-4: assign the first four tokens to the parameters %%f through %%i (first parameter is the one given in the for statement)
    • dir /b *_*_*_*: list all file where the name contains at least 3 underscores with just their file name (the output of this command is processed by the for loop)
    • setlocal EnableDelayedExpansion: expand variables at run time (otherwise assigning the parameters to variables wouldn’t work)

    For further details see help for and help dir.

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

Sidebar

Related Questions

[Note: There is another thread about this problem but it did not answer the
NOTE: I know there are many questions that talked about that but I'm still
NOTE : Right before posting this question it occurred to me there's a better
Is there a GWT Date Time Component? Note: I am already making use of
Note: There was not any question with this kind of problem here or anywhere...
Note: apparently there's a collision on the ServerName in my virtualhost entries and I
On this page , I see something interesting: Note that there is a fast-path
There is a note at the end of the atomics package summary that states:
Note: marked as community wiki. Is there a good analysis of why visual programming
Is there a keyboard command for undoing typing in iPython? Note: I am not

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.