473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 9082
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Joe Laughlin | last post by:
I've not used C much before, so I don't know how robust or good this code is. I'd appreciate any feedback or criticisms anyone has! Thanks, Joe #include <stdio.h> #include <string.h>
3
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
5
by: | last post by:
Hello Guys, I am trying to render an Xml dataset into HTML using XSLT. When I am loading the XSLT file into transform object to render it. Here is the code snippet: <!-- XslTransform...
6
by: I am Sam | last post by:
I keep getting this error and I don't know why: The path is too long after being fully qualified. Make sure path is less than 260 characters. Description: An unhandled exception occurred...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
9
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
by: wb5plj | last post by:
Hi I am having a problem passing some sql to the db2cmd via ant. This is very confusing as I am doing this exact thing elseware with no problem (just differant sql, and I have verified the sql is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.