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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:48:11+00:00 2026-05-26T11:48:11+00:00

I’m writing a batch file for automating the creation of typical folder structures for

  • 0

I’m writing a batch file for automating the creation of typical folder structures for products that we sell. I would like to be able to call my batch file with 2 optional arguments; the name of the supplier and a file for creating lots of folders at once. If no supplier is supplied the script asks via standard input who the supplier is. If no file is supplied the script asks for the name of the folder you wish to create. If a file is passed as an argument I would like the script to read the file line by line and create a folder for each line, named after the contents of that line. Here is the :readFile function:

:readFile
    echo "Reading from file: %theFile%"
    FOR /F "delims=," %%a IN (%theFile%) do (
        call:makeFolder %%a
    )
    goto:EOF

Here is the :makeFolder function that optionally takes the argument of the name of the folder to create. If no argument is supplied it asks for the name via standard input.

:makeFolder  
    if [%1]==[] (
        set /p product="Enter product name: "
    ) else (
        set product=%1
    )
    if exist "P:\%supplier%\Products\%product%" (
        echo.
        echo The folder '%product%' already exists.
        echo.
        goto:EOF
    )
    mkdir "P:\%supplier%\Products\%product%\Images\Web Ready"
    mkdir "P:\%supplier%\Products\%product%\Images\Supplied"
    mkdir "P:\%supplier%\Products\%product%\Images\Edited"
    goto:EOF

My problem is that in the :makeFolder function %1 refers to the 1st argument given on the command line, not the one provided in the :readFile function. How can I achieve this? Caveat: I’m very new to batch scripting so you may have to speak to me like I’m a bit stupid.

  • 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-26T11:48:12+00:00Added an answer on May 26, 2026 at 11:48 am

    I rebuild the file and it worked

    @echo off
    set "supplier=C:\temp\supp\"
    set "product=Car"
    echo test1,myComment,myValue > myFile.txt
    call :readFile "myFile.txt"
    EXIT /B
    
    :readFile
    echo "Reading from file: %~1"
    FOR /F "usebackq delims=," %%a IN ("%~1") do (
        call :makeFolder %%a
    )
    goto:EOF
    
    :makeFolder  
    if "%1"=="" (
        set /p product="Enter product name: "
    ) else (
        set "product=%1"
    )
    if exist "%supplier%\Products\%product%" (
        echo(
        echo The folder '%product%' already exists.
        echo(
        goto:EOF
    )
    echo "%1"
    echo mkdir "%supplier%\Products\%product%\Images\Web Ready"
    echo mkdir "%supplier%\Products\%product%\Images\Supplied"
    echo mkdir "%supplier%\Products\%product%\Images\Edited"
    goto:EOF
    

    But I would recommend to use delayed expansion, as you can got problems with the percent expansion of special characters( In this case not very relevant, as special characters are a bad choice for file/directory names).

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

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.