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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:40:01+00:00 2026-06-11T19:40:01+00:00

I need help with the following problem: I want to split a filepath into

  • 0

I need help with the following problem:

I want to split a filepath into its components inside the batch-file with CMD-commands.

First of all I determine the path where the batch file is located:

set home=%~dp0  (e.g. C:\SomeFolder\OtherFolder\)

What I need is to extract this string into:

  • C:
  • SomeFolder
  • OtherFolder

and re-concatenate these components to:

  • C:\\SomeFolder\\OtherFolder\\

This helps me loop thru the elements of the file-path

set List=!home!
:ProcessListSource
FOR /f "tokens=1* delims=\" %%a IN ("!List!") DO ( 
  if "%%a" NEQ "" ( 
        echo %%a
  )
  if "%%b" NEQ "" (
      set List=%%b
      goto :ProcessListSource
  )
)

the loop works fine, the components of the file-path echoed correctly. I thought it will be easy to change the echo statement by simple string concatenation

if "%%a" NEQ "" ( 
set foo=%foo%%%a
set foo=%foo%\\
)

the result is simply sobering. Only the backslashes will be added to the variable. Where is my mistake? Echoing %%a works fine, but in the concatenate-statement seems to be an error. I played around with quotes and ‘!’ but nothing works.

Any help on that is highly appreciated

  • 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-11T19:40:02+00:00Added an answer on June 11, 2026 at 7:40 pm

    If you only need to double the backslashes, it’s simpler to use a replace.

    set "home=%~dp0"
    set "foo=%home:\=\\%"
    echo %foo%
    

    Your code could also work:

    But the key word is here EnableDelayedExpansion (like every day).
    That’s the cause why %foo% doesn’t expand as expected.

    Add this line after your @echo off

    setlocal EnableDelayedExpansion
    

    and change your concatenation block to

    if "%%a" NEQ "" ( 
    set foo=!foo!%%a
    set foo=!foo!\\
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would really appreciate any help with the following problem: I need to be
I need help debugging some odd file behavior in Python. Take the following script
I ran into the following problem. I have an xml-file like this: <Source Name
basically i need some algorithm that fits into the following problem: i have 5
I am stuck and need outside help from JSF experts with the following problem:
I need some help with the following problem which is to work out the
I am a naive numpy user, need your help for the following problem: I
I'd really like your help with the following problem. I need to read N
I need your help with following matter. I want to read the parent tags
I need help doing the following: a preprocessor macro label(x) shall output #x, e.g.,

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.