The Setup:
- I have a set of files of type
.type1and want to batch convert them to.type2using a program I have - The converting program
Program.exe(in a folder calledTOOLS) takes two arguments-ifor InputFile and-ofor OutputFile but is unable to create folders/directories (if the output folder doesn't exist it fails) - The
.type1files are in different folders. All of these folders are in a folder calledInputFolder - I want the
.type2converted files to be outputted to theOutputFolderpreserving the folder structure of the originals - So, In the main folder I have 4 things:-
A. InputFolder:where all the input files (divided into different folders) exist
B. OutputFolder:where all the converted files should be outputted (divided into different folders matching theInputFolder)
C. TOOLS:where the converterProgram.exeexists
D. Batch Convert.bat:the batch file I wrote to batch convert the files. The contents of which are in the next section
What I tried:
rem -------Setting some general variables-------
set "BatchPath=%~dp0"
set "InputPath=%BatchPath%InputFolder\"
set "OutputPath=%BatchPath%OutputFolder\"
rem -------Saving a list of all .type1 files-------
dir /s/b/a-d "%InputPath%*.type1">"%BatchPath%TOOLS\FilesList.txt"
rem -------Starting a loop for each file listed in FilesList.txt -------
for /f "usebackq delims=" %%j in ("%BatchPath%TOOLS\FilesList.txt") do (
setlocal EnableDelayedExpansion
rem --Setting variables replacing "input string" with "output string"--
set "InputFileType2=%%~dpnj.type2"
set "OutputFile=!InputFileType2:%InputPath%=%OutputPath%!"
set "InputFilePath=%%~dpj"
set "OutputFilePath=!InputFilePath:%InputPath%=%OutputPath%!"
rem --Creating output folders--
mkdir "!OutputFilePath!"
rem --Start the converting process--
"%BatchPath%TOOLS\Program.exe" -i "%%j" -o "!OutputFile!"
endlocal
)
The Problem:
Some of the folders and the files inside the InputFolder have special characters (like ! % &) which cause problems with the converting.
Is there a way to do this with the least amount of conflict with special characters (like removing the need to EnableDelayedExpansion to remove conflict with !?
is there a way to do it without the PwerShell or the Call function?
(because I have thousands of big files and the Call function can be slow and it seems like it always tries to access the HDD first before a :Label)