这个问题确实有两部分:
我有一个文件夹,里面充满了文件和类似这样的文件夹:
C:\VIDEO\My Video 1\My Video 1.mkv
C:\VIDEO\MyVideo2\MyVideo2.mkv
C:\VIDEO\My.Video.3\My.Video.3.mkv
我需要:
1. Recursively find all *.mkv files within C:\VIDEO folder
2. Output a list of the existing Dir structure/file and folder names/paths to a .txt file
3. Then Move all *.mkv files from C:\VIDEO to another folder C:\Temp
(I do not want to retain the original folder structure during this move)
稍后,我需要:
4. Search for all *.mkv files in C:\Temp
5. Use the .txt file to help move each *.mkv file back into their original location
我想这可能需要2个单独的批处理文件。
这是我当前的进度:
@echo off
setlocal EnableExtensions EnableDelayedExpansion
:: Setup
set "SourcePath=C:\VIDEO"
set "DestPath=C:\Temp"
:: Output Items To Txt File
for /f "delims=\" %%A in ('dir "%SourcePath%"\*.mkv') DO echo "%SourcePath%">>"%DestPath%"\output.txt
:: Move Matching Items
for /f "tokens=*" %%a IN ('dir "%SourcePath%"\*.mkv') DO move /y "%SourcePath%\%%a" "%DestPath%"
有人可以帮忙吗?
答案 0 :(得分:1)
您想将树移到平坦的目标位置(知道以后要移回树并必须重新创建树)吗?为什么在地球上会那样做...
但是可以:
@echo off
set "SourcePath=C:\VIDEO"
set "DestPath=C:\Temp"
echo @echo off > MoveBack.bat
for /r "%SourcePath%" %%A in (*.mkv) do (
ECHO move "%%~fA" "%DestPath%\"
>> MoveBack.bat echo move "%DestPath%\%%~nxA" "%%~dpA"
)
echo done. To move them back, execute MoveBack.bat
与其将已移动的文件记录到文本文件中,然后再遍历该文件,不如仅构建一个“恢复”脚本。
有关%%~
修饰符的描述,请阅读for /?
的输出
注意:出于安全原因,我撤消了move
命令的撤防。如果您确定它可以正常工作,请删除ECHO
。
注意:文件夹树中可能有重复的文件名。该脚本不能解决这个问题(例如:在这种情况下,您可能会丢失数据)
答案 1 :(得分:0)
最终产品:
@echo on
set "SourcePath=H:\FIXED"
set "DestPath=H:\Temp"
echo @echo on > MoveBack.bat
for /r "%SourcePath%" %%A in (*.mkv) do (
move "%%~fA" "%DestPath%\"
>> MoveBack.bat echo move "%DestPath%\%%~nxA" "%%~dpA"
)
@echo done. To move them back, execute MoveBack.bat
现在正在工作。