By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,906 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,906 IT Pros & Developers. It's quick & easy.

help with file path exceeding 255 characters

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

<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

P: n/a
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.