Jump to content
Macro Express Forums

Looking for a simple file length test


Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 years later...

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...