Question : Script for truncating file and folder names

Okay, I'm looking for an easy fix here. I manage a file share with thousands and thousands of random, deeply nested files. My users have have painfully named all of their folders and files with extremely descriptive and exact file names. I believe some have mapped into lower levels in the file structure which is why they can create names that are way over the 256 character limit. I am having all kinds of problems from the top level down, and I want to go in and just chop everything to 15 or so characters.  I am trying to migrate these shares from Windows 2000 to Windows 2003 and I have some of the files already moved - not quite sure exactly where it breaks down - so I need to run the script on both hosts and then I'll do a differential copy by the date I managed to move the first round of files.

Can someone help with a script, please. I'm not a scripting guru and these files are too critical for me to fumble around with. I'm losing my mind over trying to get these files migrated.

Thanks for the help.

Answer : Script for truncating file and folder names

Sorry for the delay!
I like to get some good testing in myself before passing my code on...
Though, your scenario will be a better test since I was unable to find any production data to mirror (that's the way it works when you're actually looking for it - can't find it!...or maybe my users are starting to wise up!).

Anyway, the script has some commenting aboard, so you should be able to digest most of it.
Either way, the header piece is where your main attention is needed (see below).

FileLimit is the # of characters allowed.  Remember that with the unique string appended, this can go over.
FolderLimit is the same but for folder names.  I say this because, if you run this in your sandbox, have a backup copy of the test structure, or just expect that some folders/files may be processed multiple times on subsequent tests...

I.e.  
"Some ridiculously long file name that nobody in their right mind would use.xls" and
"Some ridiculously long file name that nobody in their left mind would use.xls"

would become (with the limits I've set as default):

"Some ridiculously long fi.xls"
"Some ridiculously long fi-85CB12348D22.xls"

So, obviously a subsequent run would, once again, detect the second 'corrected' file as being too long once again.
I could add logic in to avoid that, if you really need it - but I'm not sure when I could put the time back into this...lot going on this week and on-call the next two weeks... : (

The LogPath is just where the log file will be dropped.  I chose C:\ by default, which would generate a file in the format of:

Renamed_06-03-2008 3.40.15 PM.log

So that no changes get by without logging or get overwritten.

Lastly, the strFolder variable would be the parent folder of the directory listing to process.
You should be able to use "\\Servername\Share\SomePath\" - just be sure to include the trailing backslash.

It might also help if things are exceptionally tight, to map to a deeper path (much like your users are doing that got you in this mix).  For one, it potentially eliminates any problems when renaming files and secondly and most importantly, narrows the possibility of some unforseen catastrophe (But we needed those budget sheets named that way for our automation to work!).

Good luck - keep me posted. :^)

~sirbounty




1:
2:
3:
4:
5:
' +++ CUSTOMIZABLE SECTION +++
Const FileLimit = 25	'Set maximum limit for file names (excluding the extension, .EXT)
Const FolderLimit = 35  'Set maximum limit for folder names
Const LogPath = "C:\"  'Set location of output log files (must include trailing backslash)
Const strFolder = "C:\Temp\"  'Set parent folder to process (must include trailing backslash)
 
Rename_Long_File-Folder_Names.vbs (rename to .vbs to execute)
 
Random Solutions  
 
programming4us programming4us