I have a bunch of files which download from a server and I've searched this question on SO and none of the solutions work for me.
My files look like this:
date1_A.gz
date1_B.gz
date1_C.gz
date2_A.gz
date2_B.gz
date2_C.gz
I have two months worth for 10 variables. I want to define what these variables are (such as A, B, C) and push each file into a folder based on what it says in their name. So it would go from my downloads straight into a location with 10 folders where each folder has the files.
I tried to run a for loop which parsed the files and pushed them to a new location:
dir_name = "/Users/mee/Downloads/batch_files"
for subdir, dirs, files in os.walk(dir_name):
for d in dirs:
for file in files:
the_file = os.path.join(subdir, file)
if d in the_file:
new_loc = subdir + '\\' + d + '\\' + file
os.rename(the_file, new_loc)
Ideally, my files would go from my downloads into a directory I make which leads to a folder with 10 folders within it for each different data domain such as A, B, C.