|
3 | 3 | import csv |
4 | 4 | from datetime import datetime |
5 | 5 |
|
6 | | -filePath = raw_input('Enter file path (C:/Test/): ') |
| 6 | +filePath = raw_input('Enter file path (C:/Test/): ')+'/' |
7 | 7 |
|
8 | 8 | f=csv.writer(open('moveLog'+datetime.now().strftime('%Y-%m-%d %H.%M.%S')+'.csv','wb')) |
9 | 9 | f.writerow(['oldLocation']+['newLocation']) |
| 10 | +print filePath |
10 | 11 | for root, dirs, files in os.walk(filePath, topdown=True): |
11 | 12 | for name in files: |
12 | | - if os.path.join(root, name).count('/') > 9: |
| 13 | + if os.path.join(root, name).count('/') > 8: |
13 | 14 | level0 = root.index('/')+1 |
14 | 15 | level1 = root.index('/', level0)+1 |
15 | 16 | level2 = root.index('/', level1)+1 |
|
18 | 19 | level5 = root.index('/', level4)+1 |
19 | 20 | level6 = root.index('/', level5)+1 |
20 | 21 | level7 = root.index('/', level6)+1 |
21 | | - level8 = root.index('/', level7)+1 |
22 | 22 | oldLocation = os.path.join(root, name) |
23 | 23 | print oldLocation |
24 | | - newLocation = root[:level8]+name |
| 24 | + newLocation = root[:level7]+name |
25 | 25 | print newLocation |
26 | 26 | shutil.move(oldLocation, newLocation) |
27 | 27 | f.writerow([oldLocation]+[newLocation]) |
0 commit comments