Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

create sub folders using batch file

I have a file toCreateFolders.dat:

D:\main\A\1
D:\main\B\2
D:\main\B\3
D:\main\C\4
D:\main\C\5
D:\main\D\6

I wanted to create the above directories using batch script:

@ECHO ON

for /f "tokens=* delims=" %%a in (D:\toCreateFolders.dat) do (
set line=%%a

DO IF NOT EXIST !line! MD !line!
)

EXIT

It’s not working.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any suggestions?

>Solution :

I would advise that you try it like this:

@For /F "UseBackQ EOL=? Delims=" %%G In ("D:\toCreateFolders.dat") Do @If Not Exist "%%~G\." MD "%%~G"

or even like this:

@For /F "UseBackQ EOL=? Delims=" %%G In ("D:\toCreateFolders.dat") Do @MD "%%~G" 2>NUL
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading