-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocal_move.py
59 lines (52 loc) · 1.68 KB
/
local_move.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
57
58
59
def move_files(listfile):
import subprocess
import shlex
import os
f = open(listfile)
lines = f.readlines()
for line in lines:
eachfile = line.split("\"")
files = []
for s in eachfile:
if (s != '' and s!=' '):
files.append(s)
base = "/".join(files[0].split("/")[0:2])
recreate_folder(files[0], base, base + "/imported/")
command = "mv \"" + files[0] + "\" \"" + files[1]+"\""
print(command)
proc = subprocess.Popen(shlex.split(command))
out, err = proc.communicate()
if err:
print(err)
def recreate_folder(filename, base, output):
file_split = filename.split("/")
base_split = base.split("/")
i = len(base_split)
fold_string = ""
while i < len(file_split) - 1:
folder = file_split[i]
fold_string = fold_string + "/" + folder
command = "mkdir \"" + output + "/" + fold_string + "\""
proc = subprocess.Popen(shlex.split(
command), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
i += 1
return
if __name__ == "__main__":
from glob import glob
import os
import subprocess
import shlex
folders = glob("/data1/*/")
for folder in folders:
print(folder)
if os.path.isfile(folder+".listimport.txt"):
move_files(folder+".listimport.txt")
command = "rm "+folder+".listimport.txt"
print(command)
proc = subprocess.Popen(shlex.split(command))
out, err = proc.communicate()
if err:
print(err)
else:
print("no file found")