0

我有一个小烦人的东西让我发疯。我需要遍历一个目录并将子目录中包含的文件移动到另一个位置。

这适用于不包含任何空格的文件夹,但我有一些包含空格的目录,它们不起作用。我尝试在文件位置周围添加一些“”,但这也不起作用。

这就是我所拥有的:

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
) 
4

2 回答 2

2

我要做的第一件事是在括号内和 RD 命令中加上引号:

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"

那我就看看怎么样了...

这(带引号)“为我工作”:

@echo off
for /f "usebackq" %%m in (`dir /b "z:\dir with spaces"`) do (
    dir "z:\dir with spaces\%%m"
)

这(不带引号)不起作用:

@echo off
for /f "usebackq" %%m in (`dir /b z:\dir with spaces`) do (
    dir z:\dir with spaces\%%m
)
于 2013-08-26T01:53:33.767 回答
0
for /f "delims=" %%m in ('dir /b /ad "D:\adir\dir with spaces"') do (
    MOVE "D:\adir\dir with spaces\%%~m\*" "D:\bdir\dir with spaces"
    RD "D:\adir\dir with spaces\%%~m"
于 2013-08-26T04:38:33.120 回答