如何从 windows vista 中的命令行复制其他目录中的最新文件 [英] How do I copy the newest file in a directory somewhere else from the command line in windows vista

查看:39
本文介绍了如何从 windows vista 中的命令行复制其他目录中的最新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows Vista 中有一个包含许多文件的目录.我希望在批处理脚本中能够选择最新的文件并将其复制到另一个位置.任何想法我如何做到这一点?

I have a directory of many files in Windows Vista. I'd like in a batch script to be able to pick the newest file and copy it to another location. Any ideas how I do that?

推荐答案

您可以使用 for 命令调用按日期排序的目录列表,并使用它来设置环境变量,如果您将相同的变量设置为每个文件,那么它最终将被设置为最新的文件.

You can use the for command to invoke a directory listing that is sorted by date, and use it to set an environment variable, if you set the same variable to each file, then it will end up being set to the latest file.

将其放入批处理文件中:

put this into a batch file:

for /F "delims=" %%I in ('dir /b /a-d /od') do set LATEST=%%I
echo "%LATEST%"

然后您可以使用移动命令将该文件移动到您想要的任何位置.

then you can use the move command to move that file to wherever you want it.

move "%LATEST%" wherever

编辑 2011 年 2 月 10 日:修复了处理带有空格的文件名的问题.解决方法是使用delims="来禁用空间标记.感谢 Dave Potts 的修复.

EDIT 10-Feb-2011: fixed to handle filenames with spaces in them. The fix is to use "delims=" to disable tokeninzing on space. Thanks to Dave Potts for the fix.

这篇关于如何从 windows vista 中的命令行复制其他目录中的最新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆