问题描述
我工作在Win7的环境中,将创建基于在目录中列出的文件名目录中的CMD线批处理文件。
I'm working on a CMD line batch file in a Win7 environment that will create directories based upon the filenames listed in a directory.
我用这code,但创建的输出是部分的和不完整的,只有
I am using this code, but the output created is partial and incomplete with only
setlocal enabledelayedexpansion
for /r %%i in (*.wav) do (
set filename1=%%i
set folder1=!filename1:~4,10!
mkdir !folder1!
)
pause
我有此脚本保存在源目录文本格式的CMD文件,在本地硬盘,虽然它是在一个子目录。
目录输出是局部的和破碎,以混乱的输出和产生不匹配的文件的数量的目录的数目,并且创建的目录似乎窝。我研究这一点,似乎无法找到一个明确的答案。
I have this script saved as a CMD file in text format in the source directory, on a local harddrive, though it is in a subdirectory.The directory output is partial and broken, with garbled output and the numbers of directories created does not match the number of files, and the created directories seem to nest. I've researched this and can't seem to find a definitive answer.
推荐答案
这不是完全清楚什么是你所要完成。你们是不是要创建一个包含wav文件,只是没有.WAV扩展名在同一目录中的目录?如果是这样,你就错过了一些引号,你就剥文件名错误的结束了。如果这是你试图完成什么,这实际上可以用一个命令,不需要批处理脚本完成。在命令提示符下键入:
It's not entirely clear what it is you are trying to accomplish. Are you trying to create a directory within the same directory containing the wav file, just without the .wav extension? If so, you're missing some quotation marks and you're stripping the wrong end of the filename off. If that's what you are trying to accomplish, it can actually be done with a single command, no batch script needed. Type this at the command prompt:
for /r %I in (*.wav) do mkdir "%~pnI"
当然,如果你还是想在一个批处理脚本,使用 %%我
和 %%〜PNI
双百分比,而不是单一的。请参阅近一的帮助页面,了解如何
%%〜PNI
工作原理的说明。
Of course, if you still want it in a batch script, use
%%I
and %%~pnI
with double percents instead of single. See the last couple of pages of help for
for an explanation of how %%~pnI
works.
这篇关于赢7:CMD批处理文件基于文件名创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!