简体   繁体   中英

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.

You need to concatenate the path with the name like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM