python exifread在linux和mac上对图像进行排序,在windows上不起作用

齐雷克

我练习 python 并编写脚本,根据创建日期对我的照片进行排序,这是由 exifread 包完成的。我在 mac os 和 linux 上对其进行了测试,它完美无缺,但是在 Windows 上我首先遇到错误,即由于分号无法命名目录,例如“2016:06”,因此我将其更改为“2016-06” ,但脚本仍然显示如下错误:

Traceback (most recent call last):   
    File "imageSorter.py", line 25, in <module>
    sortPhotos()   
    File "imageSorter.py", line 22, in sortPhotos
    shutil.move((input_dir + name), (output_dir + name))
    File "C:\Python27\lib\shutil.py", line 326 in move
    os.unlink(src) 
    WindowsError: [Error 32] The process cannot used by another process: './landscape.jpg'

我的代码是这样的:

def sortPhotos():
    input_dir = './'

    for name in os.listdir(input_dir):
        if name.endswith('.jpg'):
            f = open(name, 'rb')
            tags = exifread.process_file(f)
            for tag in tags.keys():
                if tag in ('Image DateTime'):
                    checked_dir_year = str(tags[tag])[0:4]
                    checked_dir_month = str(tags[tag])[5:7]
                    checked_dir_no_semicolor = checked_dir_year + '-' + checked_dir_month
                    checked_dir = str(tags[tag])[0:7]
                    if not os.path.exists(checked_dir_no_semicolor):
                        os.mkdir(checked_dir_no_semicolor)
                    if checked_dir in str(tags[tag]):
                        output_dir = './' + checked_dir_no_semicolor + '/'
                        shutil.move((input_dir + name), (output_dir + name))
林派

在 Windows 上,移动文件之前,您必须关闭它。或者,您将看到上述错误消息。

你必须:f.closemove命令之前

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Python脚本在Windows上不起作用(但在Mac上可用)

gsutil在Mac和python3.5上不起作用

Python IDLE在Mac上不起作用

Python3解码在Mac上不起作用

代码在使用python 2.7.12的mac OSX上不起作用

控制台上的Spyder停止按钮在Windows和Python 3.7上不起作用

Python子进程在Windows 7上不起作用

Python pysftp put_r在Windows上不起作用

python pip install在Windows上不起作用

Boost Python模块在Windows XP上不起作用

点和分发在Python 3.3上不起作用

Python排序不起作用

Python nltk在Pycharm上不起作用

Python 脚本在 crontab 上不起作用

Python-用Gym创建的脚本在Mac上不起作用

Werkzeug-0.9.4和python3_memcached-1.51在Python 3.4上不起作用

使用Beautifulsoup和Python进行Web抓取不起作用

Python BeautifulSoup按索引对td标签进行排序,[0]和[2]有效,但[1]不起作用

sh 1 sudo找不到在ubuntu上完成的python脚本在bananian上不起作用

Subprocess.Popen中的Python双引号在Windows 10上不起作用

Python getpass在Windows Git Bash(MINGW64)上不起作用

Pyinstaller 3.4在使用Python 2.7的Windows 10上不起作用

Python -V 在 Windows 10 上不起作用或返回任何错误

python - http.server 在 Windows 上工作,但在 debian 上不起作用

Python排序/反向与argparse不起作用

在python中排序不起作用

显卡在Mac上的Windows 8.1上不起作用

ReportLab在Azure Python网站上不起作用

Python文本提取在某些pdf上不起作用