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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:17:01+00:00 2026-06-18T22:17:01+00:00

I have an input directory and an output directory . My main goal is

  • 0

I have an input directory and an output directory.

My main goal is to read of the all files in the input directory, which are of a certain extension, into an array.

Then I wish to create the tree of directories of each file in the input directory, under the output directory.

For example:

Input directory = C:\Input

Output directory = C:\Output

Input directory tree:

C:\Input\1\first.bat

C:\Input\2\3\second.bat

C:\Input\2\3\4\third.bat

C:\Input\3\1\forth.bat

I wish the output tree, which is now empty of files and folders, to look like this:

Output directory tree:

C:\Output\1\

C:\Output\2\3\

C:\Output\2\3\4\

C:\Output\3\1\

I have the following code:

For creating the array of files:

    set k=0
    for /f "eol=: delims=" %%F in ('dir /b /s %InputDir%\*.%StandardExtension%') do (
        set /a k+=1  
        set filesArray[!k!]=%%F 
    )
    set n=%k%

Create the directory for each file:

for /l %%i in (1,1,%n%) do (
    set CurrentFile=!filesArray[%%i]!
    call :CheckAndCreateDirectory %SequencesDir% !CurrentFile! %OutputDir% UpdatedOutputDir
)

And finally, the function which creates the directories:

:CheckAndCreateDirectory
set IntputDir=%1
set CurrentDir=%~dp2
set OutputDir=%3

set UpdatedOutputDir=!CurrentDir:%IntputDir%=%OutputDir%!
set %4=%UpdatedOutputDir%

if not exist %UpdatedOutputDir% (^
echo. & ^
mkdir %UpdatedOutputDir% & ^
echo.)

The thing is this:
If the input (and I guess output also) don’t contain any “special” characters like & etc., the code works.
However, if it does, the directories tree is not created.

Working input: C:\Input_Dir

Not working input: C:\Input&Dir

Any ideas?

  • 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-18T22:17:03+00:00Added an answer on June 18, 2026 at 10:17 pm

    i think i’ve a simplier solution for you :

    xcopy /T c:\input c:\ouptut
    

    Some details :

    /T Create folder structure, but do not copy files. Do not
    include empty folders or subfolders.
    /T /E will include empty folders and subfolders.

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

Sidebar

Related Questions

I have an input string which is a directory address: Example: ProgramFiles/Micro/Telephone And I
I have input fields, which I process with AJAX and send it on another
Currently I have Input: e.g., '123456789'.'+'.'987654321' Desired Pattern: Output: e.g., '123456789987654321' How can I
I have several scripts that take as input a directory name, and my program
I have developed a code that runs a map reduce job to read files
I have a C++ program which has the prototype of the main function as
I wish to read all the text files in a particular folder. The files'
I have an application that scans an input directory every five seconds and when
All: I have a unit test that is testing functionality that requires an input
I have a input and desired output xml file , but not able to

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.