I have zero coding/scripting skills, asked a friend online and looks like he's stuck as well.
I have many photos of peoples, which are named by a specific number. I also have an excel file which contains all matching numbers next to their names in 2 column. The script simply create a folder with the name and put the correct numbered files in them.
but I get this error: IndentationError: expected an indented block
here's the script
#!/usr/local/bin/python3
import os, shutil, pathlib, fnmatch, sys
def move_dir(src: str, dst: str, prefix:str, suffix: str):
if not os.path.isdir(dst):
pathlib.Path(dst).mkdir(parents=True, exist_ok=True)
for f in fnmatch.filter(os.listdir(src), prefix + suffix):
shutil.move(os.path.join(src, f), os.path.join(dst, f))
def readMapping(src: str):
mappings = {}
with open(src) as inputFile:
for line in inputFile:
args = line.rstrip().split(None, 1)
mappings[args[0]] = args[1]
return mappings
def moveFilesMatchingMapping(mappings: dict, source: str, types:str):
for num, moveTo in mappings.items():
move_dir(src=source, dst=os.path.join(source, moveTo), prefix=num, suffix=types)
sourceDir = sys.argv[2]
fileType = "*" + os.getenv("HKS_TYPE", "jpg")
mappingFile = sys.argv[1]
moveFilesMatchingMapping(mappings=readMapping(mappingFile),source=sourceDir, types=fileType)