Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime
- from os import path, walk
- from re import search, IGNORECASE
- from shutil import move
- if __name__ == '__main__':
- directoryToSearch = path.join(path.expanduser('~'), 'Desktop')
- patternToTimestamp = '^(Capture|Untitled)(\.png|\.jpg|\.gif)$'
- getTimestamp = lambda: 'Screen shot ' + datetime.now().strftime("%Y-%m-%d at %H.%M.%S %p")
- for root, _, files in walk(directoryToSearch):
- for file in files:
- if search(patternToTimestamp, file, IGNORECASE):
- _, extension = path.splitext(file)
- oldPath = path.join(root, file)
- newPath = path.join(root, getTimestamp() + extension.lower())
- move(oldPath, newPath)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement