Created
January 24, 2024 03:10
-
-
Save itkr/3fe51151525f9ba33bfd92e33580e560 to your computer and use it in GitHub Desktop.
move.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
from datetime import datetime | |
def move(suffix=None): | |
extension = suffix or 'jpg' | |
file_names = [f.name for f in os.scandir() if f.name.endswith(f'.{extension}')] | |
for file_name in file_names: | |
date_data = datetime.fromtimestamp(os.stat(file_name).st_mtime) | |
dir_name = f'{date_data.year}/{date_data.year}-{str(date_data.month).zfill(2)}' | |
if suffix: | |
dir_name = f'{date_data.year}/{date_data.year}-{str(date_data.month).zfill(2)}-{suffix}' | |
os.makedirs(dir_name, exist_ok=True) | |
try: | |
print(f'{dir_name}/{file_name}') | |
shutil.move(file_name, dir_name) | |
except Exception as e: | |
print(e) | |
def main(): | |
print(datetime.today()) | |
move(None) | |
move('bmp') | |
move('gif') | |
move('mov') | |
move('mp4') | |
move('mpg') | |
move('mts') | |
move('png') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment