【发布时间】:2018-11-09 17:18:18
【问题描述】:
我被困在这个脚本上,我正在尝试编写可以完成其中各个部分的脚本,但我似乎无法将它们组合在一起。
在一个文件夹中,有许多包含 .mp4 文件的子文件夹,其中每隔一段时间就会在任何子目录中生成一个新文件。该脚本应该能够遍历每个文件夹,并确定所有文件夹中哪个文件是最新的,并将其复制到指定文件夹,同时将其重命名为“Current.mp4”
到目前为止,我一团糟: 这会将文件复制到子目录中,但不会循环其余部分
REM Copy the most recent database backups from their folders
@echo off
REM Copy File in one destination to another --------------------------------------------
setlocal
set srcDir=P:\
set destdir=D:\
set lastmod=
pushd %srcDir%
for /f "tokens=*" %%a in ('dir /S *.mp4 /D /b /o-d /a-d /t:c') do set lastmod=%%a
:::
copy "%lastmod%" "%destDir%"
同时这个似乎是循环的,但仅指 .bat 目录中的最新文件。
setlocal
set destdir=D:\
SET srcDir=P:\
pushd %srcDir%
FOR /F "delims=" %%I in ('dir /ad /s') do (
pushd "%%~I"
pushd %srcDir%
FOR /F "delims=*" %%G IN ('DIR *=.mp4 /B /A:-D /O:D') DO SET NewestFile=%%G
popd
)
popd
:::
copy "%NewestFile%" "%destdir%"
最后重命名我想我可以弄清楚如何做最后一个。我有使用 c++ 的经验,但批处理对我来说相对较新。任何帮助将不胜感激!
谢谢
【问题讨论】:
标签: batch-file copy-paste batch-rename subdirectory