This post is in three parts.
I generate long filenames for a reason. Sometimes I run into Windows limit that the complete path to a file can’t be longer than 255 characters.
1) I Need to Keep Track of a Lot of Email Attachments
I’m a professor.
Students email me attachments.
Students also like to claim they sent me attachments.
Policing that is very hard if you use something like GMail. Keyword search is great for finding a lot when you’re not looking for much. It’s pretty lousy when you’re looking for a single item. Especially if that item is an attachment sent by a student, who may use multiple email addresses, may use an alias, and usually does not have a clue about how to name files when they may be accumulating files for years.
2) I Have a System for Keeping Track of Attachments, But It Generates Long Filenames
My solution to this problem is to use an attachment downloader. It goes through my inbox in GMail, and downloads every attachment whether I want it or not. I recommend Mail Attachment Downloader from GearMage. It’s free, and it does one thing very well.
It puts each attachment in a folder named after the sender. I put those folders in a bigger folder called attachments. I don’t have to use it much, but everything is in there.
This software also allows me to add a prefix to the filename of the attachment. This is really useful if you have 50 students who all seem to think the best filename for their homework is … wait for it … homework.docx or maybe homework.xlsx.
This is where I get myself into trouble. That prefix can include the name of the sender, the subject, the date, and a unique ID. This is extremely useful in tracking down a specific attachment from a specific person sent around a specific date, perhaps in response to a specific subject.
This works great since the attachments are now in a folder in Windows rather than in GMail (you can’t really ever get rid of them in Gmail without a purge anyway). I can use Windows Explorer to track down any attachment I ever receive. This is actually pretty useful when students run into obscure problems, often with spreadsheets, and I can vaguely recall someone having that same problem a few years back.
Once I set this system up, I can find attachments from years ago in seconds. I have trouble finding attachments from last week in GMail quicker than that.
But, having said that, this can create very long filenames.
3) Sometimes My Filenames Exceed Windows Maximum Length — How Do I Deal with That?
Remember back in the 90’s when filenames were limited to 8 characters in Windows?
When they upgraded to allow longer filenames (with spaces) enclosed in quotes, there was still a character limit: 255. That limit includes the path to the filename, and the file extension.
I exceed that limit sometimes with the path and prefix for my email attachments. Usually not excessively — the path and filenames that motivated this post ran up to 284 characters.
Windows is pretty good about dealing with those. Most operations work OK, and I rarely notice that I’ve exceeded the limit. But there are some operations that won’t go forward with the long path and filename. So then I get an error message, and when I poke around a bit I find that there are dozens of files that need to be cleaned up. Onedrive is a particular source of problems for this.
That clean up typically involves finding some part of the long filename that is not needed. This isn’t hard to do: Mail Attachment Downloader doesn’t give me a lot of options for controlling what I choose to prepend. Often this is just the student’s name: they have it in their email address, and they have an alias in quotes (that’s often the same name), and then they put their name in the subject too. And unfortunately, the better students usually include their last name in the filename of their homework.
For example. I might get an email from:
“McGanahan Skjellyfetti” firstname.lastname@example.org
With the subject:
McGanahan’s Econ Homework 11
And an attachment called:
Skjellyfetti Homework 11.xlsx
Trust me. You start prepending information like that, and you’ll go over the 255 character limit once in a while due to repeated information.
So, how to reduce the length of those filenames?
One way would be to overtype the filenames one by one.
A better way would be to do search and replace. Windows Explorer can do that, but is too limited. You can go to the command prompt, but get the same problem. Powershell is better, but still not good enough. The issue for me is that the information in the filename is too varied for the limited regex capabilities of Windows to work effectively.
I also tried some file renamers that I have around: multirenamer from PC Magazine, and Lupas Rename. Both failed at my task.
I’d like to add that at some point in my search through Powershell forums, I found the suggestion to use the “SUBST” command. This allows you to map a folder to a drive letter. This can solve much of the problem if its the path length rather than the filename length that is the issue. I believe that this command is not persistent: so you can do that mapping, use it, and it will go away when you log off.