当你从 Windows 服务器换到 Linux 服务器的时候,以前的上传目录的目录名、文件名会遇到大小写的问题。在 Windows 环境下面没有文件区分大小写的概念,而 Linux 却有严格的文件名大小写区分。 这样一来但来自 Windows 服务器上面那些文件就有可能遇到因为文件名中带有大写字母而无法被找到。需要将这些文件的文件名从大写转换为小写字母…

我需要遍历目录、子目录下的所有文件,当然也包括目录名称,于是自己写了一个

#!/usr/bin/python 
import os, sys,re 
print "Auto convert Upper filename to Lower filename" 
dir = '/image'
print "find files..."
for root,dirs,files in os.walk(dir):
    print root
    print str(len(files)) + " found."
    os.rename(root,root.lower())
    for f in files:
        filename = root.lower() + "/" + f
        if re.search('[A-Z]',filename) != None:
            print filename
            newfilename = filename.lower()
            print "Renaming", f, "to", f.lower(), "..."
            os.rename(filename, newfilename)
Python

相关文章:

  • 2021-07-11
  • 2021-11-02
  • 2022-12-23
  • 2022-01-20
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-18
  • 2021-09-13
  • 2021-06-06
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案