如何创建一个与该文件夹中的文件同名的文件夹?

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

我想完成的事情可以用 for %%i in (*) do md "%%~ni" 完成,但这只有在我的批处理文件与我要处理的文件位于同一文件夹中时才有效。我想 运行 来自另一个文件夹的批处理文件。

到目前为止,这是我尝试过的方法,但没有用。它仍在与批处理文件 运行 相同的文件夹中创建文件夹。

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

我做错了什么?没写过脚本

您需要将路径与名称连接起来 像这样

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