从命令提示符比较文件的创建日期 [英] Compare file creation dates from the command prompt

查看:247
本文介绍了从命令提示符比较文件的创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的大学,我们使用VMware相当广泛,允许在很大程度上,否则锁定的计算机管理任务的实验。我使用相同的虚拟机在家里,所以我不担心我的家乡PC的杂乱环境中,将其复制到从我的USB闪存驱动器。

At my university, we use VMware quite extensively to allow experimentation of admin tasks on otherwise heavily locked down computers. I use the same VM's at home so I don't have to worry about the cluttered environment of my native PC, by copying it to and from my USB flash drive.

该VM我用的就是snapshot'd所有我喜欢的设置,并设置恢复到快照关机,所以最好是永远不会改变。当我使用多台计算机,我有一个脚本来检查,如果虚拟机是present,如果没有,拷贝过来和日程表自动开在下次登录。

The VM I use is snapshot'd with all the settings I like, and set to revert to snapshot on shutdown, so ideally it never changes. As I use multiple computers, I have a script that checks if the VM is present, and if not, copies it over and schedules an auto-open on next login.

我现在的剧本是这样的:

My current script looks like this:

@echo off

if exist "C:\Users\[Username]\Desktop\Win7x86\Win7x86.vmx" goto open
if not exist "C:\Users\[Username]\Desktop\Win7x86\Win7x86.vmx" echo VM files not found, preparing to copy from USB
goto usb

:usb
if exist "F:" goto copy
if not exist "F:" echo Please insert USB drive.
pause
goto usb

:copy
robocopy "F:\Virtual Machines\Win7x86" "C:\Users\[Username]\Desktop\Win7x86" /mir /eta
schtasks /create /ru [Username] /rp [Password] /xml "%cd%\Win7x86 Opener.xml" /tn "Win7x86 Opener"
goto open

:open
PATH "%PROGRAMFILES%\VMware\VMware Workstation\"
START vmware.exe -x "C:\Users\[Username]\Desktop\Win7x86\Win7x86.vmx"

我的问题是这样的;有时我做出改变到虚拟机,并​​更新快照。

My problem is this; sometimes I make change to the VM, and update the snapshot.

我想我的脚本源文件(USB)连接到本地文件(台式机)的创建日期进行比较。如果本地较新,那么显然它已经自上次更新复制是罚款运行,但如果源文件是新的,那么当地的需要更新。

I want my script to compare the creation dates of the source files (USB) to the local files (desktop). If the local are newer, then obviously it's been copied since the last update and is fine to run, but if the source files are newer, then the local needs updating.

我打算使用vmware.log中作为比较的文件,因为它的小,并保持它的创建日期(有些VM文件被删除,并在虚拟机中运行过程中重新创建)。

I plan on using vmware.log as the comparison file as it's small and retains it's creation date (some VM files are deleted and re-created during the VM running process).

我已经冲刷互联网和最好的,我发现相比日期和上市最新的;但我很有限的批处理脚本知识,我不知道如何管道的Robocopy命令关闭该输出。

I've scoured the internet and the best I found compared dates and listed the newest; but with my very limited batch scripting knowledge, I have no idea how to pipe a robocopy command off that output.

推荐答案

这应该这样做。

@echo off

for /f "tokens=* usebackq" %%d in (`wmic datafile where Name^="C:\\Users\\[Username]\\Desktop\\Win7x86\\vmware.log" get creationdate ^| findstr ^"[0-9]^"`) do ( set tmpd=%%d )
set vmlocaldate=%tmpd:~0,8%

for /f "tokens=* usebackq" %%d in (`wmic datafile where Name^="F:\\Virtual Machines\\Win7x86\\vmware.log" get creationdate ^| findstr ^"[0-9]^"`) do ( set tmpd=%%d )
set vmusbdate=%tmpd:~0,8%

if %vmusbdate% gtr %vmlocaldate% goto copy

我不知道这将如何融入你的脚本,因为它需要插入USB驱动器;此刻,你可以启动你的,如果它存在,它会马上打开本地虚拟机,你必须决定,如果你总是需要插入USB驱动器,并检查创建日期,如果你只是想检查时, USB恰好是present,或者改变您的USB提示,让你跳过堵在驱动器中。

I don't know how this will fit into your script as it will need the USB drive plugged in; at the moment you can launch your and it will straight away open the local virtual machine if it exists, you have to decide if you always need to plug the USB drive in and check the creation date, if you only want to check when if the USB happens to be present, or change your USB prompt to allow you to skip plugging the drive in.

NB。它是在VBScript和PowerShell的显著更容易。

NB. It is significantly easier in both VBScript and PowerShell.

这篇关于从命令提示符比较文件的创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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