0
@echo off
set a="%USERPROFILE%\Desktop\Desktop BU\%CurrentDate%"
For /F "tokens=1-5 delims=/-" %%A in ('Date /t') do (SET CurrentDate=%%A%%B%%C)
::echo hi
mkdir "%USERPROFILE%\Desktop\Desktop BU\%CurrentDate%"
::echo dir made
dir %USERPROFILE%\Desktop\ /S /B > %TEMP%\files.txt
::echo done
For /F %%A in (%TEMP%\files.txt) do move %%A "%USERPROFILE%\Desktop\Desktop BU\%CurrentDate%\"
del %TEMP%\files.txt

上面的脚本度过了一段漫长的时光: - 它用适当的日期很好地创建了文件夹 - 在 temp 中创建文件并重定向桌面列表中的输出 - 但之后它给出了错误。找不到指定的路径我尝试了很多东西但它不起作用。您能否让我知道如何将桌面中的文件和文件夹移动到桌面中的文件夹 BACKUP。让我的桌面看起来很干净。而且我还想排除一些被移动的项目。

4

1 回答 1

0

尝试将您的for陈述更改为:

For /F "usebackq tokens=*" %%A in ("%TEMP%\files.txt") do move "%%A" "%USERPROFILE%\Desktop\Desktop BU\%CurrentDate%\"

此外,按照目前的方式,您的目标目录最后会有一个空格,并且它会尝试将桌面 BU 移动到自身中。最后,命令中不需要 /s 开关dir,因为移动目录将移动其所有子目录。试试这个:

@echo off
setlocal
set CurrentDate=%date:~0,2%%date:~3,2%%date:~6,4%
set desktop=%USERPROFILE%\Desktop
dir "%desktop%" /B | find /v "Desktop BU"> "%TEMP%\files.txt"
mkdir "%desktop%\Desktop BU\%CurrentDate%" 2>NUL
For /F "usebackq tokens=*" %%A in ("%TEMP%\files.txt") do move "%desktop%\%%A" "%desktop%\Desktop BU\%CurrentDate%\"
del "%TEMP%\files.txt"

或者这是另一种不需要中间的方式files.txt

@echo off
setlocal
set CurrentDate=%date:~0,2%%date:~3,2%%date:~6,4%
set desktop=%USERPROFILE%\Desktop
mkdir "%desktop%\Desktop BU\%CurrentDate%" 2>NUL
for /f "tokens=*" %%A in ('dir "%desktop%" /b ^| find /v "Desktop BU"') do (
    move "%desktop%\%%A" "%desktop%\Desktop BU\%CurrentDate%\"
)
于 2013-02-12T15:09:06.483 回答