Title
import os
import shutil
import pandas
import csv
"""
new_dir = 'Inflamed_10x'
directory = 'Cohort2_InflamedFinal'
isExist = os.path.exists(new_dir)
if not isExist:
os.makedirs(new_dir)
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
if f.find("10X") < 0:
continue
shutil.move(f, new_dir)
"""
directory = 'Cohort2_InflamedFinal'
with open('csv_data.csv', newline='') as csvfile:
csv_data = csv.reader(csvfile)
col_cnt = len(next(csv_data))
for filename in os.listdir(directory):
print(filename)
import os
import shutil
import pandas
import csv
directory = 'Cohort2_InflamedFinal'
csvfile = open('csv_data.csv', newline='')
for filename in os.listdir(directory):
csvfile.seek(0)
csv_data = csv.reader(csvfile)
# f = os.path.join(directory, filename)
temp = filename.split(".")
f = temp[0]
for csv_row in csv_data:
# for csv_col_idx in range(0, col_cnt):
# print(csv_col_idx, csv_row[csv_col_idx])
match_temp = csv_row[1]
match = match_temp[3:len(match_temp)]
if (match == f):
new_dir = 'Inflamed_' + csv_row[4].lower()
isExist = os.path.exists(new_dir)
if not isExist:
os.makedirs(new_dir)
file_with_path = os.path.join(directory, filename)
shutil.move(file_with_path, new_dir)
# rename the file
break
import os
import shutil
import pandas
import csv
directory = 'Cohort2_NonInflamedFinal'
csvfile = open('csv_data.csv', newline='')
for filename in os.listdir(directory):
csvfile.seek(0)
csv_data = csv.reader(csvfile)
# f = os.path.join(directory, filename)
temp = filename.split(".")
f = temp[0]
for csv_row in csv_data:
# for csv_col_idx in range(0, col_cnt):
# print(csv_col_idx, csv_row[csv_col_idx])
match_temp = csv_row[1]
match = match_temp[3:len(match_temp)]
if (match == f):
new_dir = 'NonInflamed_' + csv_row[4].lower()
isExist = os.path.exists(new_dir)
if not isExist:
os.makedirs(new_dir)
file_with_path = os.path.join(directory, filename)
shutil.move(file_with_path, new_dir)
# rename the file
break
import os
import shutil
import pandas
import csv
directory = "Inflamed"
directory2 = "_notebooks"
# open the file, and then for each row in the csv file...
csvfile = open('csv_data.csv', newline='')
csv_data = csv.reader(csvfile)
for csv_row in csv_data:
new_dir_temp = csv_row[0]
new_dir = new_dir_temp[0:12]
isExist = os.path.exists(new_dir)
if not isExist:
os.makedirs(new_dir) # make a new directory based on the first 11 characters of column Name
csvfile = open('csv_data.csv', newline='') # open the csv file
for filename in os.listdir(directory): # loop through all the files in Inflamed
csvfile.seek(0)
csv_data = csv.reader(csvfile)
temp = filename.split(".")
f = temp[0]
for csv_row in csv_data:
match_temp = csv_row[1]
match = match_temp[3:len(match_temp)]
if (match == f): # find match for a given file in Inflamed
actual_name = csv_row[0]
for cur_file in os.listdir(): # for each file in _notebooks...
if os.path.isdir(cur_file): # if the file is a directory ...
if (actual_name[0:12] == cur_file): # and if the directory is equal to the first 11 characters of the given image file...
file_with_path = os.path.join(directory, filename) # create a path for the image file
shutil.move(file_with_path, cur_file) # and move the image to the directory that has the matching name