Before using Python to do the Chinese extraction tool, now do a copy of the file of the gadget, compare records as follows:
Requirements Description:
require a fixed folder under the continuous generation of some fixed file name files, for the main program to operate, the main program for stress testing.
Requirements Analysis:
The simplest is to move a source folder (Srcfile) continuously to the target folder (Dstfile)
Solution:
To be as concise as possible, use the configuration file as the basis for the input variables. Not much to say, on the code:
Configuration file:Config_copy.ini as follows:
The Python implementation code is as follows:
Python Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st 22 23 24 25 26
|
|
#-*-Coding:utf-8-*- #!/usr/bin/python # filename:copyfile.py # codedtime:2015-5-6 Import OS Import Shutil Import Configparser Def excute (): iniconf = Configparser. Configparser () Iniconf. Read (' Config_copy.ini ') SourceDir = iniconf. Get (' setting ', ' SourceDir ') TargetDir = iniconf. Get (' setting ', ' TargetDir ') While True: For file in Os.listdir (SourceDir): SourceFile = Os.path. Join (SourceDir, file) TargetFile = Os.path. Join (TargetDir, file) If not os.path.exists (targetfile): Shutil.copyfile (SourceFile, TargetFile)
if __name__ = = ' __main__ ': Excute () |
Experience:
1, the reason why Python efficiency is high, is that there are so many ready-made modules such as: Shutil, Configparser, etc. for you to use, oneself as long as the hands of the organization can be.
2, C + + a few hours of things, Python may only take a few minutes to do, do some gadgets, really convenient, lovely python ...
notable places to note:
1. Shutil.copyfile throws an exception:
Exception Analysis:
Solution: