代码之家  ›  专栏  ›  技术社区  ›  Seth

无法判断samba共享上是否存在文件

  •  0
  • Seth  · 技术社区  · 15 年前

    我知道文件名是 file001.txt FILE001.TXT ,但我不知道是哪一个。该文件位于我通过samba装载点访问的Windows机器上。

    中的函数 os.path 看起来他们好像对案件不敏感,但是 open

    >>> from os.path import exists, isfile
    
    >>> exists('FILE001.TXT')
    True
    
    >>> isfile('FILE001.TXT')
    True
    
    >>> open('FILE001.TXT')
    Traceback (most recent call last):
      File "<console>", line 1, in <module>
    IOError: [Errno 2] No such file or directory: 'FILE001.TXT'
    
    >>> open('file001.txt')    # no problem
    

    所以,我的问题是:

    1. 有没有办法在不打开文件(或列出文件所在的目录)的情况下确定文件名?

    2. 为什么 区分大小写时 操作系统路径 不是吗?


    谢谢你的回答,但是 this isn't a python problem

    3 回复  |  直到 9 年前
        1
  •  1
  •   Kevin Stricker    15 年前

    您可以尝试将nocase添加到fstab中的mount中,如下面的示例所示(如果它还不存在的话):

    //server/acme/app    /home/joe/.wine/drive_c/App    cifs    guest,rw,iocharset=utf8,nocase,file_mode=0777,dir_mode=0777    0    0
    

    Found a link explaining normcase

    normcase是一个有用的小函数 认为 mahadeva.mp3和mahadeva.mp3是 同样的文件。例如,在Windows上 而Mac OS,normcase将转换 与UNIX兼容的系统,它将 返回未更改的文件名。

    这就告诉你开门很可能是 总是 在Windows文件系统上需要小写文件名。

        2
  •  0
  •   Pablo Santa Cruz    15 年前

    回答你的问题:

    1. 你可以用 stat
    2. Windows共享文件系统不区分大小写。
        3
  •  0
  •   Nick Presta    15 年前
    def exists(path):
        try:
            open(path).close()
        except IOError:
            return False
        return True