os.path.exists returns False on Windows although file exists (MAX_PATH 260 Windows API problem?)

Viewed 360

I am getting a false negative on a file that exists with os.path.exists.

path = '\\\\fgcz-biobeamer.uzh.ch\\Data2San\\p3061\\Proteomics\\TIMSTOF_1\\spfammatter_20200317\\3-17-2020_22-17-14_200ngHeLa_stdPASEF_100minGT__MSdataReduction_moderate_Rep1_520_1_Slot1-46.d\\stdPASEF_100minGT_MSdataReduction_moderate_520.m\\microTOFQImpacTemAcquisition.method'

os.path.exists(path) # returns false

len(path) # returns 260

I did some googling and what I found is:

In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters.

(https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file)

Is there a different python API that can handle paths of that length I could use?

Some windows tools can't handle those paths (although I did create this file using robocopy which is a windows tool).

PS C:\Users\Admin> ls \\fgcz-biobeamer.uzh.ch\Data2San\p3061\Proteomics\TIMSTOF_1\spfammatter_20200317\3-17-2020_22-17-1
4_200ngHeLa_stdPASEF_100minGT__MSdataReduction_moderate_Rep1_520_1_Slot1-46.d\stdPASEF_100minGT_MSdataReduction_moderate
_520.m\


    Directory: \\fgcz-biobeamer.uzh.ch\Data2San\p3061\Proteomics\TIMSTOF_1\spfammatter_20200317\3-17-2020_22-17-14_200n
    gHeLa_stdPASEF_100minGT__MSdataReduction_moderate_Rep1_520_1_Slot1-46.d\stdPASEF_100minGT_MSdataReduction_moderate_
    520.m


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
------        3/18/2020  12:45 AM            156 desktop.ini
------        3/17/2020  10:17 PM          14301 hystar.method
------        3/18/2020  12:45 AM              0 lock.file
------        3/18/2020  12:45 AM         129055 microTOFQImpacTemAcquisition.method

but


PS C:\Users\Admin> ls \\fgcz-biobeamer.uzh.ch\Data2San\p3061\Proteomics\TIMSTOF_1\spfammatter_20200317\3-17-2020_22-17-1
4_200ngHeLa_stdPASEF_100minGT__MSdataReduction_moderate_Rep1_520_1_Slot1-46.d\stdPASEF_100minGT_MSdataReduction_moderate
_520.m\microTOFQImpacTemAcquisition.method
ls : Cannot find path '\\fgcz-biobeamer.uzh.ch\Data2San\p3061\Proteomics\TIMSTOF_1\spfammatter_20200317\3-17-2020_22-17
-14_200ngHeLa_stdPASEF_100minGT__MSdataReduction_moderate_Rep1_520_1_Slot1-46.d\stdPASEF_100minGT_MSdataReduction_moder
ate_520.m\microTOFQImpacTemAcquisition.method' because it does not exist.
At line:1 char:1
+ ls \\fgcz-biobeamer.uzh.ch\Data2San\p3061\Proteomics\TIMSTOF_1\spfamm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (\\fgcz-biobeame...uisition.method:String) [Get-ChildItem], ItemNotFound
   Exception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

I am using Python 3.7.7 64bit

>>> import sys
>>> sys.maxsize > 2**32
True
0 Answers
Related