I want to add "source_paths" to my script so that it can run on an external directory using cmd.bat
Example cmd.bat
echo off
Rename.py [Folder_Images] [listname.txt]
pause
code script Rename.py
import pathlib
IMG_DIR = pathlib.Path('.\Folder_Images')
with open('listname.txt') as jabber:
content = jabber.read().splitlines()
director = sorted(IMG_DIR.iterdir())
for src, dest in zip(director, content):
src.rename(IMG_DIR / f'{dest}{src.suffix}')
I found this code I tried to add I get an error no such file.
Code
if __name__ == '__main__':
import os
import sys
source_paths = []
if len(sys.argv) > 1:
for i, path in enumerate(sys.argv[1:]):
if i < 2 and not os.path.isfile(path):
raise ValueError(f'Not a valid path or file does not exist: {path}')
source_paths.append(path)
if i < 2:
raise ValueError(f'Three path arguments needed')
source_paths = source_paths[0:2]
source_paths = [os.path.abspath(path) for path in source_paths]
Rename(source_paths[0], source_paths[1])