help with file path exceeding 255 characters

Y

yguan08

I have trouble of obtaining the file size of a file because the
fullpath exceeds 255 characters. I get this message with
os.path.getsize(fullpath).

fullpath = r"\\LOSSSFS002\NWE_TECHNICAL\05. UK\Schiehallion (204_25a)
\Amos&Burke_P559\07. Technical (Subsurface)\06. Well Planning\Amos
\Daily Reports\Wireline\final_204_25a_8z\204_25a_8z\Run_1A
\HRLA_SP_DSI_PEX_HNGS_ECRD\ANCILLARY\Amos_204_25a-8Z_GR_to_surface_3-
Mar-2008_DSI_HRLA_TLD_MCFL_047PUC.las"

fsize = os.path.getsize(fullpath)


WindowsError: [Error 206] The filename or extension is too long:

The same thing with os.stat(fullpath).

I tried using the relative path, but it does not work with the message
fname not found.

dir = os.path.dirname(fullpath)
fname = os.path.basename(fullpath)
os.chdir(dir)
filesize = os.path.getsize(fname)

Is there a walk around of this?
 
A

Arnaud Delobelle

I have trouble of obtaining the file size of a file because the
fullpath exceeds 255 characters. I get this message with
os.path.getsize(fullpath).

fullpath = r"\\LOSSSFS002\NWE_TECHNICAL\05. UK\Schiehallion (204_25a)
\Amos&Burke_P559\07. Technical (Subsurface)\06. Well Planning\Amos
\Daily Reports\Wireline\final_204_25a_8z\204_25a_8z\Run_1A
\HRLA_SP_DSI_PEX_HNGS_ECRD\ANCILLARY\Amos_204_25a-8Z_GR_to_surface_3-
Mar-2008_DSI_HRLA_TLD_MCFL_047PUC.las"

fsize = os.path.getsize(fullpath)


WindowsError: [Error 206] The filename or extension is too long:

The same thing with os.stat(fullpath).

I tried using the relative path, but it does not work with the message
fname not found.

dir = os.path.dirname(fullpath)
fname = os.path.basename(fullpath)
os.chdir(dir)
filesize = os.path.getsize(fname)

Is there a walk around of this?

Disclaimer: I am not a Windows user

Might this help? http://forum.altap.cz/viewtopic.php?p=2353

Alternately, use a better OS :)
 
Y

yguan08

I have trouble of obtaining the file size of a file because the
fullpath exceeds 255 characters. I get this message with
os.path.getsize(fullpath).
fullpath = r"\\LOSSSFS002\NWE_TECHNICAL\05. UK\Schiehallion (204_25a)
\Amos&Burke_P559\07. Technical (Subsurface)\06. Well Planning\Amos
\Daily Reports\Wireline\final_204_25a_8z\204_25a_8z\Run_1A
\HRLA_SP_DSI_PEX_HNGS_ECRD\ANCILLARY\Amos_204_25a-8Z_GR_to_surface_3-
Mar-2008_DSI_HRLA_TLD_MCFL_047PUC.las"
fsize = os.path.getsize(fullpath)
WindowsError: [Error 206] The filename or extension is too long:
The same thing with os.stat(fullpath).
I tried using the relative path, but it does not work with the message
fname not found.
dir = os.path.dirname(fullpath)
fname = os.path.basename(fullpath)
os.chdir(dir)
filesize = os.path.getsize(fname)
Is there a walk around of this?

Disclaimer: I am not a Windows user

Might this help?  http://forum.altap.cz/viewtopic.php?p=2353

Alternately, use a better OS :)

I tried, but still the same error:

WindowsError: [Error 206] The filename or extension is too long: '\\\\?
\\UNC\\LOSSSFS002\\NWE_TECHNICAL\\05. UK\\Schiehallion (204_25a)\
\Amos&Burke_P559\\07. Technical (Subsurface)\\06. Well Planning\\Amos\
\Daily Reports\\Wireline\\final_204_25a_8z\\204_25a_8z\\Run_1A\
\HRLA_SP_DSI_PEX_HNGS_ECRD\\ANCILLARY\\Amos_204_25a-8Z_GR_to_surface_3-
Mar-2008_DSI_HRLA_TLD_MCFL_047PUC.las'
 
J

John Machin

I have trouble of obtaining the file size of a file because the
fullpath exceeds 255 characters. I get this message with
os.path.getsize(fullpath).

fullpath = r"\\LOSSSFS002\NWE_TECHNICAL\05. UK\Schiehallion (204_25a)
\Amos&Burke_P559\07. Technical (Subsurface)\06. Well Planning\Amos
\Daily Reports\Wireline\final_204_25a_8z\204_25a_8z\Run_1A
\HRLA_SP_DSI_PEX_HNGS_ECRD\ANCILLARY\Amos_204_25a-8Z_GR_to_surface_3-
Mar-2008_DSI_HRLA_TLD_MCFL_047PUC.las"

fsize = os.path.getsize(fullpath)


WindowsError: [Error 206] The filename or extension is too long:

The same thing with os.stat(fullpath).

I tried using the relative path, but it does not work with the message
fname not found.

dir = os.path.dirname(fullpath)
fname = os.path.basename(fullpath)
os.chdir(dir)

I suspect that the cause of the problem here is that while *x OSes have
just one current working directory, Windows has one cwd per drive.
filesize = os.path.getsize(fname)

Is there a walk around of this?

At the DOS command level, you can do
subst x: very\long\path
and then refer to
x:filestem.ext
where x is any unused drive letter.

This seems to work:

HTH,
John
 
Y

yguan08

I have trouble of obtaining the file size of a file because the
fullpath exceeds 255 characters. I get this message with
os.path.getsize(fullpath).
fullpath = r"\\LOSSSFS002\NWE_TECHNICAL\05. UK\Schiehallion (204_25a)
\Amos&Burke_P559\07. Technical (Subsurface)\06. Well Planning\Amos
\Daily Reports\Wireline\final_204_25a_8z\204_25a_8z\Run_1A
\HRLA_SP_DSI_PEX_HNGS_ECRD\ANCILLARY\Amos_204_25a-8Z_GR_to_surface_3-
Mar-2008_DSI_HRLA_TLD_MCFL_047PUC.las"
fsize = os.path.getsize(fullpath)
WindowsError: [Error 206] The filename or extension is too long:
The same thing with os.stat(fullpath).
I tried using the relative path, but it does not work with the message
fname not found.
dir = os.path.dirname(fullpath)
fname = os.path.basename(fullpath)
os.chdir(dir)

I suspect that the cause of the problem here is that while *x OSes have
just one current working directory, Windows has one cwd per drive.
filesize = os.path.getsize(fname)
Is there a walk around of this?

At the DOS command level, you can do
     subst x: very\long\path
and then refer to
     x:filestem.ext
where x is any unused drive letter.

This seems to work:

 >>> import os
 >>> os.system('subst x: c:\\junk')
0
 >>> f = open('x:foo.py')
 >>> f.read()
"print 'hello'\n"
 >>>

HTH,
John- Hide quoted text -

- Show quoted text -

Good idea. But subst does not see to work with path that has spaces.
It gives "Incorrect number of parameters"
 
J

John Machin

Good idea. But subst does not see to work with path that has spaces.
It gives "Incorrect number of parameters"

If any DOS command-line argument includes spaces, you need to quote it.

os.system(r'subst x: "c:\my big fat path\rab oof\etc etc etc"')
 
Y

yguan08

If any DOS command-line argument includes spaces, you need to quote it.

os.system(r'subst x: "c:\my big fat path\rab oof\etc etc etc"')

Yes, it works now. I am getting more on windows after coming a long
way from Unix. Thanks a lot.
 
R

Roger Upole

I have trouble of obtaining the file size of a file because the
fullpath exceeds 255 characters. I get this message with
os.path.getsize(fullpath).

fullpath = r"\\LOSSSFS002\NWE_TECHNICAL\05. UK\Schiehallion (204_25a)
\Amos&Burke_P559\07. Technical (Subsurface)\06. Well Planning\Amos
\Daily Reports\Wireline\final_204_25a_8z\204_25a_8z\Run_1A
\HRLA_SP_DSI_PEX_HNGS_ECRD\ANCILLARY\Amos_204_25a-8Z_GR_to_surface_3-
Mar-2008_DSI_HRLA_TLD_MCFL_047PUC.las"

fsize = os.path.getsize(fullpath)


WindowsError: [Error 206] The filename or extension is too long:

The same thing with os.stat(fullpath).

I tried using the relative path, but it does not work with the message
fname not found.

dir = os.path.dirname(fullpath)
fname = os.path.basename(fullpath)
os.chdir(dir)
filesize = os.path.getsize(fname)

Is there a walk around of this?

You need to use the '\\?\UNC\' prefix and specify the path
in unicode (Python 2.5 and up).

Roger
 
G

Gabriel Genellina

WindowsError: [Error 206] The filename or extension is too long: '\\\\?
\\UNC\\LOSSSFS002\\NWE_TECHNICAL\\05. UK\\Schiehallion (204_25a)\
\Amos&Burke_P559\\07. Technical (Subsurface)\\06. Well Planning\\Amos\
\Daily Reports\\Wireline\\final_204_25a_8z\\204_25a_8z\\Run_1A\
\HRLA_SP_DSI_PEX_HNGS_ECRD\\ANCILLARY\\Amos_204_25a-8Z_GR_to_surface_3-
Mar-2008_DSI_HRLA_TLD_MCFL_047PUC.las'

In addition to starting with \\?\UNC\, the path has to be an Unicode
string, and already normalized (that is, it cannot contain . nor ..
components)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top