+ Reply to Thread
Results 1 to 17 of 17

Working with Paths over 255 characters - file count

  1. #1
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Working with Paths over 255 characters - file count

    Hi All,

    I'm having some problems coming up with a work around for paths over the maximum character length. At present I'm getting a Runtime 76 - Path Not Found error.

    I know the ideal solution would be to get the excesive folder structure corrected but the user base is large and there are other dependacies that don't really make that a viable solution.

    I'm using the following function to count the number of files in folders / subfolders which is then used in a progress bar:
    Please Login or Register  to view this content.
    As I said all works fine until it encounters lengthy paths.

    I've done some research into workarounds but having trouble understanding how they work in order to integrate into this code.
    I've seen something about adding prefixes to the file path to cope with longer paths, "\?\" for relative and "\\?\unc\" for absolute paths (https://stackoverflow.com/questions/...onger-than-260).
    And seen something called ShortPath which makes the filepath unreadable to the user but not an issue here (https://stackoverflow.com/questions/...paths-over-260).
    For the life of me I can't seem to get either method integrated into this function - I'm sure that's down to my own ignorance but I have tried everything I can think of here.

    Or I'm open to an alternative way of counting the number of files that doesn't hit an issue with long paths.

    As always, any assistance appreciated.

    Thanks, TC

  2. #2
    Valued Forum Contributor
    Join Date
    11-02-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    459

    Re: Working with Paths over 255 characters - file count

    added 11-8-17
    Drive Mapping.jpg ~ what I was hoping to do is bypass the long folder names my Drive Mapping (you may want to check with your local IT dept?) but you can Brows the folders to get to your destination. So, the drive letter Z could be designated for a long file path. I did see an article (Below) as I'm not an expert either in fiddling with FSO. Keep at it, sounds like your very close!

    just found something ~ https://stackoverflow.com/questions/...onger-than-260

    older suggestion:
    Can you 'Map' the drive? So, if your path is: S:\serverName\folder1\folder2\folder3\folder4\folder5\LookyHere ~ can you map a new drive letter "P:" that would take the place for everything up to & including the LookyHere...then you can just reference drive P. It's worth a shot?!
    Last edited by queuesef; 11-08-2017 at 11:23 AM.

  3. #3
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Working with Paths over 255 characters - file count

    I think I kind of get what you're saying here but I have no experience with this so not sure entirely how it would work.
    I'm not specifying the path directly - the FSO is picking that up - and that's the problem I'm having; how to amend the path either via adding Unicode (?) prefixes or using ShortPath. I can't work out how to integrate that into the code.

  4. #4
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Working with Paths over 255 characters - file count

    This is getting even stranger... It looks like the path lengths might not actually be what is causing the error, rather that VBA can't even see files / folders with paths over the max length.

    I set up a dummy folder structure with about 6 or 7 sub folders each with a long name and placed files in each. Windows does try to stop you doing this but it lets you rename a folder to a longer name.

    I then run the following code:
    Please Login or Register  to view this content.
    As I rename one of the top level folders to a longer name the less far down VBA appears to be able to see. Anything over the max length and it just doesn't register. But it's not giving me the same Runtime Error 76 Path Not Found as it if for other folders. I created my dummy structure on the same drive to be sure.

    It's worrying that VBA is simply not picking everything up, but giving no error - yet in other situations it is...? I'm guessing there must be something else causing the 76 error. But I can't think what.

    Anyone else replicating the same behaviour?

    TC

  5. #5
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Working with Paths over 255 characters - file count

    Further testing has revealed that if the path is exactly 259 characters long then the Runtime Error 76 occurs (presumably because on adding a "\" to look for files it hits the 260 limit [not 255 like I thought]) - anything over this just doesn't even get seen.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Working with Paths over 255 characters - file count

    Perhaps this
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  7. #7
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Working with Paths over 255 characters - file count

    Thanks xlnitwit - that is exactly what I was trying to do! but just couldn't work out how to integrate the 'shortpath'.

    It has left me with a subsequent issue - is there anyway to retrieve the long path back from the short path? Or maintain it in unison somehow?

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Working with Paths over 255 characters - file count

    Honestly, I don't know- I can't see how with this approach, but will see if there is another one that can be adapted.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Working with Paths over 255 characters - file count

    deleted ...
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Working with Paths over 255 characters - file count

    Hi Queuesef,

    Thanks for the more detailed explanation - I had started going down this route before xlnitwit pointed me in the right direction with the shortpath. There were some issues with it though.
    If the user already has that drive letter mapped for example. And how to incorirate into recursive code - could end up exhausting the number of drive letters availiable.

    So for me ShortPath was better. The only issue I have now - is how to maintain the file path in full for communicating back to the user. I'll post an update below with the code I'm using to check certain file attributes.

  11. #11
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Working with Paths over 255 characters - file count

    This is the recursive code I'm using to check certain file attributes, this isn't the full code but a stripped down version to give you and idea of the structure and what I was thinking with trying to store the full path to a string:

    Please Login or Register  to view this content.
    All objects seem to have the shortpath associated with them - which I guess makes sense. So I don't think there's anyway to obtain the full path again, e.g. from the Fil object.

    The problem I'm having when trying to store to a string is know when to delete the last folder and when to retain it, for the next sub (sub / subsub / subsubsub / etc) folder. I'm not sure this method would be possible either.

  12. #12
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Working with Paths over 255 characters - file count

    This seems to work in limited testing
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Working with Paths over 255 characters - file count

    Okay so this is using the UNC method - I'm hitting a problem with it setting the objFolder - each time it's Nothing.

    Please Login or Register  to view this content.
    Here's a bit more of the code which will hopefully shed some light - I'm adapting existing code so don't fully understand all of what it's doing - I'm not certain that objFolder nor objFolderItem is even needed, they are public variables but I can't find them anywhere else in the subsequent code:
    Please Login or Register  to view this content.
    I'll try taking them out and see what effect it has.

    Thanks again for your input here xlnitwit, much appreciated.

  14. #14
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Working with Paths over 255 characters - file count

    They don't seem to be used for anything in what you posted.

  15. #15
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Working with Paths over 255 characters - file count

    Yep I've removed them form everything as I can't see the purpose. I am however now getting another error I'd not encountered before in trying to obtain the 'Last Saved By' attribute or 'owner.'

    I don't know if this is a problem with the unc file path - it wasn't happening before - but I can see the file is missing the attribute but I can't seem to skip it if nothing there, not even using On Error Resume next. The Error is 70 - Permission Denied. Here's the code:

    Please Login or Register  to view this content.
    And the error is occurring on this line:
    Please Login or Register  to view this content.
    Feel like I'm chasing my tail with this!

  16. #16
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Working with Paths over 255 characters - file count

    I have been testing this over the last couple of days and the error has not re-occurred. Therefore I'm marking this as Solved. Thanks for your help, very much appreciated.

  17. #17
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Working with Paths over 255 characters - file count

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. About file paths
    By Moragtao in forum Excel General
    Replies: 1
    Last Post: 07-19-2017, 05:10 AM
  2. Linked File Paths Change When File is Moved
    By belewfripp in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-06-2013, 12:18 PM
  3. [SOLVED] Dynamic file paths. HELP!
    By christhweatt in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-07-2013, 04:22 PM
  4. Export To Inf file & Zip the Files from the given file paths picking every 10 rows
    By vivekhalder in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2012, 03:59 AM
  5. Replies: 3
    Last Post: 04-29-2009, 03:59 AM
  6. [SOLVED] file paths
    By hr in forum Excel General
    Replies: 0
    Last Post: 12-07-2005, 01:10 PM
  7. Relative file paths
    By Jim in forum Excel General
    Replies: 7
    Last Post: 05-24-2005, 07:02 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1