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?