I want to write a small script for a friend who has a bunch of images restored after deletion ( 50 gigs ) and I'm trying to use the pathlib module for this. But the renamed files are moved into the working directory. How does rename method work?
Here is the initial code:
Here is the initial code:
path = Path(args.path) files = (f for f in path.rglob('*') if f.is_file()) for f in files: ext = f.suffix if ext != '.py': stats = f.stat() name = Path(datetime.fromtimestamp(stats.st_mtime).strftime('%Y%m%d-%H%M%S')) f.rename(name)The directory contains two more with the images inside them. When I run the code all images are renamed and moved to the working directory ( the root scan directory for example. The default path is '.').