问题描述
我有我发疯这个小小的恼人的事情。
我需要遍历目录并移动一个包含子目录中的文件到另一个位置。
这工作正常,不包含任何空格的文件夹,但我有包含空格,不工作的一些目录。
我试着加入一些围绕文件的位置,但这并不能工作。
这是我有:
FOR / F有usebackq%%的('DIR / B D:\\ ADIR \\与spaces` DIR)M做(
移动/ YD:\\ ADIR \\目录用空格\\ %%米\\ *。*,D:\\ bdir \\目录用空格
RD / Q D:\\ ADIR \\带空格的目录\\ %%米
)
我会做的第一件事就是把括号内和RD命令报价:
FOR / F有usebackq%%的('DIR / BD:\\ ADIR \\目录以空格`)M做(
移动/ YD:\\ ADIR \\目录用空格\\ %%米\\ *。*,D:\\ bdir \\目录用空格
RD / QD:\\ ADIR \\目录用空格\\ %% M
然后我会看看怎么回事...
这(带引号),为我工作:
关闭@echo
FOR / F有usebackq%%的('DIR / BZ:\\目录以空格`)M做(
DIRZ:\\目录用空格\\ %% M
)
这(不带引号)不工作:
关闭@echo
FOR / F有usebackq%%的('DIR / B Z:\\目录与spaces`)M做(
DIR Z:\\目录用空格\\ %%米
)
I have this tiny annoying thing that is driving me nuts.I need to loop through a directory and move files contained within a subdir to another location.
This works fine for folders that don't contain any spaces, but I have some directories that contain spaces, which do not work.I've tried adding some "" around the file location, but that doesn't work either.
This is what I have:
for /f "usebackq" %%m in (`dir /b D:\adir\dir with spaces`) do (
MOVE /Y "D:\adir\dir with spaces\%%m\*.*" "D:\bdir\dir with spaces"
RD /q D:\adir\dir with spaces\%%m
)
The first thing I would do is put quotes inside the parentheses and in the RD command:
for /f "usebackq" %%m in (`dir /b "D:\adir\dir with spaces"`) do (
MOVE /Y "D:\adir\dir with spaces\%%m\*.*" "D:\bdir\dir with spaces"
RD /q "D:\adir\dir with spaces\%%m"
Then I would see how it goes...
This (with quotes) "works for me":
@echo off
for /f "usebackq" %%m in (`dir /b "z:\dir with spaces"`) do (
dir "z:\dir with spaces\%%m"
)
This (without the quotes) does NOT work:
@echo off
for /f "usebackq" %%m in (`dir /b z:\dir with spaces`) do (
dir z:\dir with spaces\%%m
)
这篇关于用空格批处理文件循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!