用于移动文件的 Windows 批处理脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15968949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows batch script to move files
提问by user2273893
I need to move files from one directory to another in windows, and I need to write this in a batch script.
我需要在 Windows 中将文件从一个目录移动到另一个目录,我需要在批处理脚本中编写它。
We have written a SQL job where backup files will be created every 4 hours on the D:
drive and last 4 backup files will be saved and others will be deleted.
我们编写了一个 SQL 作业,其中每 4 小时在D:
驱动器上创建一次备份文件,最后 4 个备份文件将被保存,其他文件将被删除。
I need to write a batch script to move these files from the D:
drive to the E:
drive every 10 hours.
我需要编写一个批处理脚本,每 10 小时将这些文件从D:
驱动器移动到E:
驱动器。
Can anyone help me to write this script.
谁能帮我写这个脚本。
回答by SwampYeti
Create a file called MoveFiles.bat with the syntax
使用语法创建一个名为 MoveFiles.bat 的文件
move c:\Sourcefoldernam\*.* e:\destinationFolder
then schedule a task to run that MoveFiles.bat every 10 hours.
然后安排一个任务,每 10 小时运行一次 MoveFiles.bat。
回答by Batch Programmer
You can try this:
你可以试试这个:
:backup
move C:\FilesToBeBackedUp\*.* E:\BackupPlace\
timeout 36000
goto backup
:backup
move C:\FilesToBeBackedUp\*.* E:\BackupPlace\
timeout 36000
goto backup
If that doesn't work try to replace "timeout" with sleep. Ik this post is over a year old, just helping anyone with the same problem.
如果这不起作用,请尝试用睡眠替换“超时”。我这个帖子已经一年多了,只是帮助任何有同样问题的人。
回答by Ahddib
This is exactly how it worked for me. For some reason the above code failed.
这正是它对我的工作方式。由于某种原因,上面的代码失败了。
This one runs a check every 3 minutes for any files in there and auto moves it to the destination folder. If you need to be prompted for conflicts then change the /y to /-y
这个每 3 分钟运行一次检查那里的任何文件,并自动将其移动到目标文件夹。如果需要提示冲突,请将 /y 更改为 /-y
:backup
move /y "D:\Dropbox\Dropbox\Camera Uploads\*.*" "D:\Archive\Camera Uploads\"
timeout 360
goto backup
回答by uFreaky
move c:\Sourcefoldernam\*.* e:\destinationFolder
^ This did not work for me for some reason
^ 由于某种原因,这对我不起作用
But when I tried using quotation marks, it suddenly worked:
但是当我尝试使用引号时,它突然起作用了:
move "c:\Sourcefoldernam\*.*" "e:\destinationFolder"
I think its because my directory had spaces in one of the folders. So if it doesn't work for you, try with quotation marks!
我认为这是因为我的目录在其中一个文件夹中有空格。因此,如果它不适合您,请尝试使用引号!