Application from demand
I am a photo maniac, even more so since I bought a DSLR! My hard drive is certainly not enough, so every backup is a very painful thing! So think of their own to do a self-help to solve the program automatically, just in learning python, and then use Python call Robocopy wrote an automatic backup of the gadget for their own use, since then farewell to the painful backup ERA! 5 lines of code, at the same time Robocopy replication faster than the copy and paste Windows, greatly saving the backup time;
On the Code
#导入os 模块import os#获取源目录source=raw_input("pls input source documnet:")#获取目标目录des=raw_input ("pls input destination document:")#定义复制命令,robocopy 的命令参数详解, /s 复制子目录,但不复制空的子目录; /copyall 复制所有文件信息;/MON:n:监视源;发现多于 n 个更改时再次运行;/MOT:m:监视源;如果更改,在 m 分钟时间内再次运行。cop=("robocopy %s %s /s /copyall /mot:1 /mon:2 ")%(source,des)#执行robocopy 命令robo=os.system(cop)
Concrete Use effect See:
I have written Python packaged as an. exe file, which can then be used on any platform,
After the first copy is completed, the program will not automatically exit, will always monitor the source folder, if there are two file changes, or 1 minutes of changes, will be the change part of the copy.
Python 5 Line code farewell backup painful times