python - How to streamline file moving script? -


i wrote clunky script move specific files located in 1 folder 3 different folders. 3 lists specify files should grouped , moved new folder. although script works, ugly , inefficient. how can improve on structure of script make file-moving process more elegant , streamlined?

import os, shutil  # location of input files os.chdir = r'c:\path\to\input_imagery' ws = os.chdir  # lists of file sets need moved area1 = ["4111201_ne.tif", "4111201_nw.tif"] area2 = ["4111202_ne.tif", "4111202_nw.tif"] area3 = ["4111207_nw.tif", "4111301_ne.tif"]  # output folders folder_area1 = r'c:\out\area1' folder_area2 = r'c:\out\area2' folder_area3 = r'c:\out\area3'  area in area1:     input1 = os.path.join(ws, area)     output1 = os.path.join(folder_area1, area)     shutil.move(input1, output1)  area in area2:     input1 = os.path.join(ws, area)     output1 = os.path.join(folder_area2, area)     shutil.move(input1, output1)  area in area3:     input1 = os.path.join(ws, area)     output1 = os.path.join(folder_area3, area)     shutil.move(input1, output1) 

why not pack up

to_move = [   [ 'source_dir1', 'target_dir1', { 'source_file' : 'dest_file', 'source2' : 'dest2'}]   [ 'source_dir2', 'target_dir2', { 'source_file' : 'dest_file', 'source2' : 'dest2'}]   ] 

and iterate on all.

i use dictionary files because moving them. guarantees sources unique in dict.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -