Recently, the project is relatively tight, and the project has entered a later stage. The test is too busy. It was originally a task of testers and I was a new employee. So the boss handed me a task, it is to check whether there is memory leakage in a project developed on the Win8 platform, and use Windows's built-in perfmon. MSC monitors and records the monitoring data at the same time. Because there are not many test cases, you need to copy the same test cases multiple times and put them in the same directory.ProgramThe background is opened repeatedly. However, in Windows 8, if you perform multiple copies on the same file, the file name is simply added with a copy (1) after the original file. However, if so, files of the same size are arranged together. The sorting function of Windows 8 cannot sort files in disorder, will cause errors to program monitoring. If you use a program to open a file when a series of large files are together, the memory will fluctuate. This kind of floating will be unstable and cause errors in the test, which is intolerable. Therefore, the best way is to rename all the files and name them randomly. Then, the sorting can be disrupted in this way, and then the test is ongoing.
The program demo is as follows:
# Renamerand. py # Yanggd 2012/9/7 # Get file name, and then rename the file # After renamed, the name likes this: [A-Za-Z] [A-Za-Z] [0-9] [0-9] [A-Za-Z] [0-9] Import Random Import Osexistname = [] Def Renamerand (PATH): filelist = OS. listdir (PATH) # List the file name Rangeletter = ( ' Abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ' ) For Oldfilenameandext In Filelist: newfilename = Random. Choice (rangeletter) + random. Choice (rangeletter) + \ STR (random. randrange ( 10) + STR (random. randrange (10) + random. Choice (rangeletter) + STR (random. randrange (10 )) While Newfilename. Upper () In Existname: newfilename = Random. Choice (rangeletter) + random. Choice (rangeletter) + \ STR (random. randrange ( 10) + STR (random. randrange (10) + random. Choice (rangeletter) + STR (random. randrange (10 ) Existname. append (newfilename. Upper () [oldfilename, fileext] = Oldfilenameandext. Split ( ' . ' , 1 ) Newfilenameandext = [Newfilename, fileext] newfilenameandext = ' . ' . Join (newfilenameandext) path = OS. Path. abspath (PATH) pathsrc = Path + ' \\ ' + Oldfilenameandext pathdst = Path + ' \\ ' + Newfilenameandext OS. Rename (pathsrc, pathdst) If _ Name __ = ' _ Main __ ' : Renamerand (R ' F: \ practice code \ testdata \ rename ' )