首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >windows命令行在最后x分钟修改文件

问windows命令行在最后x分钟修改文件
EN

Stack Overflow用户
提问于 2013-01-30 15:15:50
回答 2查看 7.4K关注 0票数 1

我想从windows文件夹中抓取文件,并根据上次修改的日期和时间将它们复制到另一个文件夹中。

是否有方法比较批处理文件中的日期时间?

我的意思是得到分钟小时,日,月,上一次文件修改的年份,并将其与当前的系统分钟小时日月年进行比较?

EN

回答 2

Stack Overflow用户

发布于 2013-01-30 21:49:11

首先我要做的是

代码语言:javascript
复制
@Echo Off

For /f "tokens=1,2,3 delims=-" %%a in ('date /t') do (set mydateDD=%%a&& set mydateMM=%%b&& set mydateYY=%%c)
For /f "tokens=1,2 delims=:" %%a in ('time /t') do (set mytimeHH=%%a&& set mytimeMM=%%b)
echo _%mydateDD%_
echo _%mydateMM%_
echo _%mydateYY%_
echo _%mytimeHH%_
echo _%mytimeMM%_
echo %date%=date
echo %time%=time

结果非常接近,但我在这一年中得到了一个不太酷的空间:

30 _01_ _2013 _ 21 _47_ 30-01-2013=date 21:47:35,93=time

票数 0
EN

Stack Overflow用户

发布于 2013-01-31 06:43:41

为什么不使用xcopy..。盖伊

代码语言:javascript
复制
xcopy c:\test_CMD\COLLECT c:\test_CMD\EXTRACT /D:%mm%-%dd%-%yyyy% /M

Syntax
      XCOPY source [destination] [options]

Key
   source      : Pathname for the file(s) to be copied.

   destination : Pathname for the new file(s).

   [options] can be any combination of the following:

Source Options

   /A           Copy files with the archive attribute set (default=Y)

   /M           Copy files with the archive attribute set and
                turn off the archive attribute, use this option
                when making regular Backups (default=Y)

   /H           Copy hidden and system files and folders (default=N)

   /D:mm-dd-yyyy
                Copy files changed on or after the specified date.
                If no date is given, copy only files whose
                source date/time is newer than the destination time.

   /U           Copy only files that already exist in destination.

   /S           Copy folders and subfolders

   /E           Copy folders and subfolders, including Empty folders.
                   May be used to modify /T.

   /EXCLUDE:file1[+file2][+file3]...

               The files can each contain one or more full or partial
               pathnames to be excluded.
               When any of these match any part of the absolute path of
               a SOURCE file, then that file will be excluded.
               For example, specifying a string like \obj\ or .obj will exclude
               all files underneath the directory obj or all files with the
               .obj extension respectively.

Copy Options

   /W           Prompt you to press a key before starting to copy.
   /P           Prompt before creating each file.

   /Y           Suppress prompt to confirm overwriting a file.
                may be preset in the COPYCMD env variable.
   /-Y          Prompt to confirm overwriting a file.

   /V           Verify that the new files were written correctly.
   /C           Continue copying even if an error occurs.

   /I           If in doubt always assume the destination is a folder
                e.g. when the destination does not exist.

   /Z           Copy files in restartable mode. If the copy is interrupted part
                way through, it will restart if possible. (use on slow networks)

   /Q           Do not display file names while copying.
   /F           Display full source and destination file names while copying.
   /L           List only - Display files that would be copied.

Destination Options

   /R           Overwrite read-only files.

   /T           Create folder structure, but do not copy files. Do not
                include empty folders or subfolders. 
                /T /E will include empty folders and subfolders.

   /K           Copy attributes. XCOPY will otherwise reset read-only attributes.

   /N           If at all possible, use only a short filename (8.3) when creating
                a destination file. This may be necessary when copying between disks
                that are formatted differently e.g NTFS and VFAT, or when archiving 
                data to an ISO9660 CDROM.

   /O           Copy file Ownership and ACL information.

   /X           Copy file audit settings (implies /O).
XCOPY will accept UNC pathnames

永远不要重新发明轮子:p

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14607294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档