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_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? -- http://mail.python.org/mailman/listinfo/python-list
Re: help with file path exceeding 255 characters
On May 13, 3:49 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] 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_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 :-) > > -- > 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\\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' -- http://mail.python.org/mailman/listinfo/python-list
Re: help with file path exceeding 255 characters
On May 13, 4:38 pm, John Machin <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] 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_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" -- http://mail.python.org/mailman/listinfo/python-list
Re: help with file path exceeding 255 characters
On May 13, 5:31 pm, John Machin <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > On May 13, 4:38 pm, John Machin <[EMAIL PROTECTED]> wrote: > >> [EMAIL PROTECTED] 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. -- http://mail.python.org/mailman/listinfo/python-list