|
3 | 3 | import shutil |
4 | 4 | import csv |
5 | 5 | from datetime import datetime |
| 6 | +import itertools |
6 | 7 |
|
7 | 8 | filePath = raw_input('Enter file path (C:/Test/): ') |
8 | 9 |
|
|
11 | 12 | f2=csv.writer(open('unsampledLog'+datetime.now().strftime('%Y-%m-%d %H.%M.%S')+'.csv','wb')) |
12 | 13 | f2.writerow(['oldLocation']+['newLocation']) |
13 | 14 |
|
14 | | -print filePath |
15 | | - |
16 | 15 | for root, dirs, files in os.walk(filePath, topdown=True): |
17 | 16 | print root |
18 | | - number = 1 |
19 | | - while number < len(files): |
20 | | - oldLocation = os.path.join(root, files[number]) |
| 17 | + print files |
| 18 | + sampledFiles = itertools.islice(files, 1, None, 10) |
| 19 | + for sampledFile in sampledFiles: |
| 20 | + print sampledFile |
| 21 | + oldLocation = os.path.join(root, sampledFile) |
21 | 22 | project = root[root.rfind('/')+1:] |
22 | 23 | root1 = root[:root.rfind('/')] |
23 | 24 | root2 = root1[:root1.rfind('/')] |
24 | 25 | newLocation = os.path.join(root2, 'sampled', project) |
25 | 26 | if not os.path.exists(newLocation): |
26 | | - os.makedirs(newLocation) |
27 | | - print newLocation |
28 | | - newLocation = os.path.join(newLocation, files[number]) |
| 27 | + os.makedirs(newLocation) |
| 28 | + newLocation = os.path.join(newLocation, sampledFile) |
29 | 29 | print oldLocation |
30 | 30 | print newLocation |
31 | 31 | f.writerow([oldLocation]+[newLocation]) |
32 | | - number = number + 10 |
33 | 32 | shutil.move(oldLocation, newLocation) |
34 | 33 | oldUnsampledLocation = os.path.join(root) |
35 | 34 | if oldUnsampledLocation != filePath: |
36 | 35 | project = root[root.rfind('/')+1:] |
37 | 36 | root1 = root[:root.rfind('/')] |
38 | 37 | root2 = root1[:root1.rfind('/')] |
39 | 38 | newUnsampledLocation = os.path.join(root2, 'unsampled', project) |
40 | | - print oldUnsampledLocation |
41 | | - print newUnsampledLocation |
42 | 39 | f2.writerow([oldUnsampledLocation]+[newUnsampledLocation]) |
43 | 40 | shutil.move(oldUnsampledLocation, newUnsampledLocation) |
0 commit comments