[英]Using Python, recursively create symbolic links for all .jpg files created within the last 24 hours
I store my photo library organized by year and event, for example:我存储按年份和事件组织的照片库,例如:
/mnt/mediapool/images1/2020/Day at the beach/IMG1.JPG
/mnt/mediapool/images1/2020/Day at the beach/IMG2.JPG
/mnt/mediapool/images1/2021/Sunset/IMG15.JPG
Using Python3, how can I recurse through all my images and create symbolic links inside another directory that list all images created within the last 24 hours (and 7-days, 30-days, etc..)?使用 Python3,我如何递归遍历我的所有图像并在另一个目录中创建符号链接,该目录列出了过去 24 小时(以及 7 天、30 天等)内创建的所有图像?
For example:例如:
/mnt/mediapool/sorted/last-24h/IMG1.JPG (symbolic link to /mnt/mediapool/images1/2020...)
/mnt/mediapool/sorted/last-24h/IMG2.JPG (symbolic link to /mnt/mediapool/images1/2020...)
/mnt/mediapool/sorted/last-24h/IMG3.JPG (symbolic link to /mnt/mediapool/images1/2020...)
/mnt/mediapool/sorted/last-7d/IMG1.JPG (symbolic link to /mnt/mediapool/images1/2020...)
Use os.walk(/mnt/mediapool/images1/)
to recurse through that directory tree.使用
os.walk(/mnt/mediapool/images1/)
递归遍历该目录树。
os.path.join()
to create a full path from the parent dir to the fileos.path.join()
创建从父目录到文件的完整路径For each file, check the creation time or the modified time with os.stat()
对于每个文件,使用
os.stat()
检查创建时间或修改时间
Create the necessary directory tree for where the link would go, using os.makedirs
使用
os.makedirs
为链接 go 的位置创建必要的目录树
Create the link to the target image with os.symlink()
or pathlib.Path.symlink_to()
使用
os.symlink()
或pathlib.Path.symlink_to()
创建到目标图像的链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.