如何code一个批处理文件来复制和重命名最近日期的文件? [英] How to code a batch file to copy and rename the most recently dated file?
问题描述
我想code一个批处理文件,在一个给定的文件夹,因为它仅复制最近日期的文件到另一个目录在本地计算机上,并同时将其重命名。
我发现一个非常类似的问题在这里。
<一个href=\"http://stackoverflow.com/questions/97371/batch-script-to-copy-newest-file\">http://stackoverflow.com/questions/97371/batch-script-to-copy-newest-file
和设法凑齐从其他论坛上低于code过,但都碰壁,因为它只会导致自己被复制到目标文件夹中的批处理文件。这并不重要,我这个批文件本身坐落在为了这个运行。
源文件夹是C:! BATCH和目标文件夹是C:\\ DROP
在code以下是道歉,如果这是一个有目共睹的答案,但它的字面首次涉足编码批处理文件,我...谢谢!
关闭@echoSETLOCAL EnableDelayedExpansionPUSHD C:\\!批量FOR / F令牌= * delims =%%的G('DIR / B / OD)就(将最新= %% G)复制!最新! C:\\ DROP \\暂停
我觉得这个小器官功能障碍综合征使你的脚本,做你想要的东西。
上@echo
SETLOCAL DisableDelayedExpansion
PUSHDC:\\批
SETLOCAL EnableDelayedExpansion FOR / F令牌= * delims =%%的G('DIR / B / OD)就(将最新= %% G) 副本%最新%C:\\ DROP \\ newname.txt 暂停
POPD
newname.txt ...是新的名称:)
I'm trying to code a batch file to copy only the most recently dated file in a given folder to another directory on the local machine, and simultaneously rename it as it does.
I've found a very similar question here
http://stackoverflow.com/questions/97371/batch-script-to-copy-newest-file
and have managed to cobble together the below code from other forums too, but have hit a brick wall as it only results in the batch file itself being copied to the destination folder. It doesn't matter to me where the batch file itself sits in order for this to run.
The source folder is C:! BATCH and the destination folder is C:\DROP
The code is below, apologies if this is a glaringly obvious answer but it's literally the first foray into coding batch files for me... Thanks!
@echo off
setLocal EnableDelayedExpansion
pushd C:\! BATCH
for /f "tokens=* delims= " %%G in ('dir/b/od') do (set newest=%%G)
copy "!newest!" C:\DROP\
PAUSE
I think this small mods enable your script to do what you want
@echo on
setLocal DisableDelayedExpansion
pushd "C:\! BATCH"
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%G in ('dir/b/od') do (set newest=%%G)
copy %newest% C:\DROP\newname.txt
PAUSE
POPD
newname.txt ... is the new name :)
这篇关于如何code一个批处理文件来复制和重命名最近日期的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!