469,643 Members | 1,486 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

help with file path exceeding 255 characters

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_1 A
\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?
Jun 27 '08 #1
8 8259
yg*****@gmail.com writes:
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_1 A
\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 :-)

--
Arnaud
Jun 27 '08 #2
On May 13, 3:49*pm, Arnaud Delobelle <arno...@googlemail.comwrote:
ygua...@gmail.com writes:
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_1 A
\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 :-)

--
Arnaud- Hide quoted text -

- Show quoted text -
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\\R un_1A\
\HRLA_SP_DSI_PEX_HNGS_ECRD\\ANCILLARY\\Amos_204_25 a-8Z_GR_to_surface_3-
Mar-2008_DSI_HRLA_TLD_MCFL_047PUC.las'
Jun 27 '08 #3
yg*****@gmail.com wrote:
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_1 A
\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
Jun 27 '08 #4
On May 13, 4:38*pm, John Machin <sjmac...@lexicon.netwrote:
ygua...@gmail.com wrote:
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_1 A
\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"

Jun 27 '08 #5
yg*****@gmail.com wrote:
On May 13, 4:38 pm, John Machin <sjmac...@lexicon.netwrote:
>ygua...@gmail.com wrote:
>>I have trouble of obtaining the file size of a file because the
fullpath exceeds 255 characters. I get this message with
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.
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"')

Jun 27 '08 #6
On May 13, 5:31*pm, John Machin <sjmac...@lexicon.netwrote:
ygua...@gmail.com wrote:
On May 13, 4:38 pm, John Machin <sjmac...@lexicon.netwrote:
ygua...@gmail.com wrote:
I have trouble of obtaining the file size of a file because the
fullpath exceeds 255 characters. I get this message with
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.
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"')
Yes, it works now. I am getting more on windows after coming a long
way from Unix. Thanks a lot.
Jun 27 '08 #7

<yg*****@gmail.comwrote in message
news:41**********************************@z72g2000 hsb.googlegroups.com...
>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_1 A
\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


Jun 27 '08 #8
En Tue, 13 May 2008 18:06:13 -0300, <yg*****@gmail.comescribió:
On May 13, 3:49*pm, Arnaud Delobelle <arno...@googlemail.comwrote:
>ygua...@gmail.com writes:
I have trouble of obtaining the file size of a file because the
fullpath exceeds 255 characters. I get this message with
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\\R un_1A\
\HRLA_SP_DSI_PEX_HNGS_ECRD\\ANCILLARY\\Amos_204_25 a-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)

--
Gabriel Genellina

Jun 27 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Joe Laughlin | last post: by
3 posts views Thread by StGo | last post: by
5 posts views Thread by | last post: by
6 posts views Thread by I am Sam | last post: by
9 posts views Thread by santosh | last post: by
1 post views Thread by Rahul | last post: by
reply views Thread by wb5plj | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.