简体   繁体   English

批处理脚本可根据上次修改日期或创建日期将文件从一个网络共享复制到另一个网络共享

[英]Batch script to copy a file from one network share to another based on lastmodified or creation date

I have two network shared drives: lets call them: DriveA and DriveB . 我有两个网络共享驱动器:让我们称之为: DriveADriveB

There are two files which get generated at DriveA on a daily basis, and I want to copy the latest files to DriveB/Folder1/fileA and DriveB/Folder2/fileB everyday. 每天在DriveA上生成两个文件,我想每天将最新文件复制到DriveB / Folder1 / fileADriveB / Folder2 / fileB

Can anyone please provide me solution wherein I can copy the files based on creation date: 任何人都可以向我提供解决方案,其中我可以根据创建日期复制文件:

  1. Copy fileA( creation date: 17July ) to DriveB/Folder1 将文件A( 创建日期:7月17日 )复制到DriveB / Folder1
  2. Copy fileB( creation date: 17July ) to DriveB/Folder2 将fileB( 创建日期:7月17日 )复制到DriveB / Folder2

I did come up with a solution but, it copies the file based on "today's date". 我确实提出了一个解决方案,但是它根据“今天的日期”复制文件。

SET usernameID=useremail@domain.com SET usernameDOMAIN=11111111 SET password=pwd@1234 net use "\\\\111.444.222.777\\FOLDER" /USER:%usernameID% %password% /persistent:no set source=\\\\222.111.333.444\\FOLDER\\FOLDER2\\Report_ net use "\\\\DOMAIN\\storage\\2012-0151_hms_ux\\Hadoop\\LiveDataLandingZoneDWH" /user:usermail@domain.com pwd@1234 /persistent:no set dest=\\\\code1\\storage\\2012-0151_hms_ux\\Hadoop\\LiveDataLandingZoneDWH\\Input\\Report\\Report_ for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set MyDate=%%x set today=%MyDate:~0,4%%MyDate:~4,2%%MyDate:~6,2% echo %today% :copy copy "%source%%today%0700.csv" "%dest%%today%0700.csv" IF ERRORLEVEL 0 goto disconnect goto end pause :disconnect goto end pause :end pause

EDIT 1: 编辑1:

Now I'm using the below command to copy the files on the date 16/Jul/2017: xcopy C:\\Users\\Desktop\\report\\ActualHRC_*.csv C:\\Users\\Downloads /D:07-16-2017 pause 现在,我使用以下命令在2017年7月16日复制文件: xcopy C:\\Users\\Desktop\\report\\ActualHRC_*.csv C:\\Users\\Downloads /D:07-16-2017 pause

How can I provide the /D:mdy dynamically? 如何动态提供/D:mdy I mean, the variables should take the m , d and y from the system. 我的意思是,变量应从系统中获取mdy

Thanks in advance! 提前致谢!

I think you have made things way too complicated. 我认为您使事情变得太复杂了。 There is a very simple solution: xcopy /Y/D . 有一个非常简单的解决方案: xcopy /Y/D

If you just type xcopy /? 如果只输入xcopy /? you can see all the options. 您可以看到所有选项。 For the /D option, it says: 对于/D选项,它表示:

Copies files changed on or after the specified date. 复制在指定日期或之后更改的文件。 If no date is given, copies only those files whose source time is newer than the destination time. 如果没有给出日期,则仅复制源时间比目标时间新的那些文件。

There is also robocopy , which is also built into windows, offers even more options, and is allegedly capable of copying from network share to network share using UNC pathnames. 还有robocopy ,它也内置在Windows中,提供了更多选项,并且据称能够使用UNC路径名从网络共享复制到网络共享。 (so, no drive mapping necessary.) (因此,不需要驱动器映射。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 File.Copy()从网络共享到同一台机器上的另一个共享是否通过网络复制文件? - Does File.Copy() from a network share to another share on the same machine copy the file over the network? 批处理脚本可将具有特定日期和格式的文件的文件夹从一个位置复制到另一个位置 - Batch Script to copy folders with files having a specific date and format from one location to another a 将数据从一个文件复制到另一个文件不起作用(批处理脚本) - Copy data From one file to another file doesn't work (Batch Script) 如何使用批处理脚本将文件从一台Windows计算机复制到特定驱动器中的另一台Windows计算机? - How to copy the file from one windows machine to another windows machine in a particular drive using batch script? 根据网络共享中文件的最后修改时间戳更新批处理文件 - Update a batch file based on the last modified timestamp on a file in a network share 将元数据从一个文件批量复制到另一个文件(EXIFTOOL) - Batch copy metadata from one file to another (EXIFTOOL) 批处理文件可将文件从一个目录复制到另一个目录 - Batch file to copy files from one directory to another 如何在批处理文件中将选定的文件从一个文件夹复制到另一个文件夹? - How to copy selected files from one folder to another in Batch file? 批处理:将一个txt文件的内容复制到另一个 - Batch: copy content of one txt file into another 将文件从一个文件夹复制到另一个文件夹,然后使用当前日期/时间重命名,并使用PowerShell或Python脚本重命名新文件 - Copy file from one folder to another and then rename using current date/time and new file ext using PowerShell or Python script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM