-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCopyFiles.py
52 lines (39 loc) · 1.58 KB
/
CopyFiles.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
import os
import shutil
import pandas as pd
"""
@ Date: 15 November 2022
@ DateMod: 02 December 2022
@ author: AMAL JOSEPH VARGHESE
@ email: [email protected]
@ github: https://github.com/amaljova
This script copies DICOM data to a newly created, properly arranged folder.
Run CollectMetaData.py and generate the required metadata csv file before running it.
"""
def makeFolders(dir_name):
'''To create a directory/directories if it/they are basent'''
if not os.path.exists(dir_name):
os.makedirs(dir_name)
def getpath(x):
return x.split("\\")[-1] # only for windows
# return x.split("/")[-1] # uncomment for Linux or MacOS
def copyFiles(metadata_file,dest_dir):
datasheet = pd.read_csv(metadata_file)
for i, row in datasheet.iterrows():
try:
# -------------------data Copying---------------------------------
dest_dir = os.path.join(dest_dir, row['Patient_ID'])
dest_dir = os.path.join(dest_dir, row['Study_Instance_UID'])
dest_dir = os.path.join(dest_dir, row['Series_Instance_UID'])
makeFolders(dest_dir)
dest_file = os.path.join(dest_dir, getpath(row['File_Path']))
shutil.copy(row['File_Path'], dest_file)
except Exception as e:
print(e)
if __name__ == "__main__":
# Edit here
metadata_file = "0_outfile.csv"
dest_dir = "dest_folder"
print("Started.")
copyFiles(metadata_file,dest_dir)
print("Done.")