relisys
relisys

Reputation: 41

How can I create a folder with the same name as the file names in that folder?

What I want to accomplish can be done with for %%i in (*) do md "%%~ni" however this only works if my batch file is in the same folder as the files I want to process. I want to run a batch file from a another folder.

This is what I have tried so far and it's not working. It is still creating the folders in the same folder I run the batch file.

for %%i in ("D:\test1\*") do  md "D:\test2\"  "%%~ni" 

What am I doing wrong? I have not written a script before.

Upvotes: 0

Views: 1798

Answers (1)

matmahnke
matmahnke

Reputation: 452

You need to concatenate the path with the name like this

for %%i in ("D:\test1\*") do  md "D:\test2\%%~ni"

Upvotes: 2

Related Questions