-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBatchMove.py
57 lines (42 loc) · 1.27 KB
/
BatchMove.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
A script that ::
-- Create a sub-folder in current directory
-- Select every file with specified extension
-- Move files to created folder above
"""
import os
import shutil
source = './'
destination = './sub/'
files = os.listdir(source)
'''Create the directory '''
def createFolder(dir):
try:
if not os.path.exists(dir): # Check if directory does not exist
os.makedirs(dir) # Create the specified directory
except OSError:
print ('Error: Creating directory. ' + dir)
def moveFiles():
for file in files:
#if ('.py' in file): # Check if file contains .srt in the name
if (file.endswith(".srt")): # Check if the file ends with .srt
shutil.move(file, destination) # Move file to the destination folder
else:
print ("No file with .srt extension")
# Creates a folder in the current directory called sub
createFolder('./sub/')
# Move files with specified extension to folder
moveFiles()
"""
import shutil
import os
source = '/path/to/source_folder'
dest1 = '/path/to/apple_folder'
dest2 = '/path/to/intel_folder'
files = os.listdir(source)
for f in files:
if (f.startswith("Apple") or f.startswith("apple")):
shutil.move(f, dest1)
elif (f.startswith("Intel") or f.startswith("intel")):
shutil.move(f, dest2)
"""