Cory Posted June 2, 2010 Report Share Posted June 2, 2010 Does anyone know of a quick and dirty way to test a file name and path for maximum length? I know the limitations and could write a mathematical test but if there's an easier technique I'd be interested in knowing it. Normally I never test if a file exceeds but recently one of my macros has been bonking into it every once in a blue moon. The macro disposes emails into a file system and suggests the subject as the file name. The problem is some email creators tend to write a novel in their subject and it can create a file name that's too big. Quote Link to comment Share on other sites More sharing options...
acantor Posted June 2, 2010 Report Share Posted June 2, 2010 Would it be enough to test the length of the subject line? As novel-length subjects are the culprit, perhaps you could chop off everything after x characters, or warn the user that their subject must be shortened before continuing. Quote Link to comment Share on other sites More sharing options...
kevin Posted June 2, 2010 Report Share Posted June 2, 2010 Would it be enough to test the length of the subject line? Or you could test the length of the full path. Another approach that could work is to map a drive letter deep into the path. If the path is normally something like this: c:\Documents and Settings\This Users Name\Local Settings\Temporary Internet Files\AntiPhishing\ThisIsALongSubjectTurnedIntoAFileNameThatMakesThePathTooLong_2CEDBFBC-DBA8-43AA-B1FD-CC8E6316E3E2.dat It could be referenced as S:\ThisIsALongSubjectTurnedIntoAFileNameThatMakesThePathTooLong_2CEDBFBC-DBA8-43AA-B1FD-CC8E6316E3E2.dat This may help you by shortening the full pathname to something that will work. But the pathname may still be too long for other programs like those that copy or backup files unless they too use the drive letter. Quote Link to comment Share on other sites More sharing options...
Cory Posted June 10, 2010 Author Report Share Posted June 10, 2010 Given that in this case the file does not exist yet I realize the folly of my question. In this particular case I need to calculate the link of the path which will vary and do like you say and truncate. But the user has the option to create a custom name so I'll want a loop back test that does the math and does not let them advance if too long. It's too bad I cant set the form field length to simply prohibit too many characters. The other oddity is what to do if that file name already exists. I have a macro that handles this and adds integer versions in parenthesis but that too is a varying number of characters. So to do it properly would take a lot of code and odds are I'll do it in some slightly sleazy fashion. Geesh, all this just to make sure the file name isn't too long! Quote Link to comment Share on other sites More sharing options...
Cory Posted June 10, 2010 Author Report Share Posted June 10, 2010 This may help you by shortening the full pathname to something that will work. But the pathname may still be too long for other programs like those that copy or backup files unless they too use the drive letter. That is exactly the problem. And I have seen times when UNC paths cause a problems just like a drive mapping. When the UNC path \\server\data\ actually points to something like d:\Customer Data\Billing Reports\ which is longer. Works for the user but the backup blows up. Quote Link to comment Share on other sites More sharing options...
terrypin Posted October 2, 2014 Report Share Posted October 2, 2014 Would it be practical (for files over a certain length, say 259, calculated in the usual way, depending on where you're starting from) to substitute a 'working version' of the filename with all characters after say the first 20 randomised and then truncated to say 20? Making this a 40 character full filename.The aim being to retain visual identification yet ensure that statistically the filename would be unique. --Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.