I need a VBS Script to convert long file names to and from short file names (backup and restore long file names)

Since ISO and UDF File Systems do not support as much characters as NTFS, I need a VBS Script to convert long file names to and from short file names (backup and restore long file names); maybe creating an external text file to store long file names, then renaming files and folders to a short a name (backup). To restore, open text file which stores long files and folders names, then renamig them from the short name to the long name. It must be recursive (rename all files, folders and subfolders inside a main folder I specify). The idea is to burn CD's/DVD's with short names (long names backuped), and restore long files and folders names after copying them from CD/DVD to HDD.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

* I think the simplest method might be to copy the (long name) file and then check to see what it's name is, if different, then output a line to your rename crossreference file.

* Since ISO/UDF might use a different long-to-short algorithm than NTFS, you might want to consider bundling all the files into a single file, which is then saved to your media with an 8.3 name.  Think zip.

* If you are sure that you your ISO/UDF name will be the same as the NTFS short name, then you might quickly do the following before your copy:
Dir /x > DirList.txt

The "Dir /x" outputs both short and long names.  The copy command will include the DirList.txt file, so your restore script will be able to rename the files.
asgarcymedAuthor Commented:
I have two goals with this question - backup and restore long file names, and learn VBS. I know that VBS can do what I am asking, however I am a beginner in VBS yet. Thus I decided to post this question in this section (Programming > Languages > Visual Basic).
* You can use the FileCopy statement to copy files.
* You can use Shell to execute the DIR command
* when restoring files, you will use the Open statement and Do...Loop to process the lines in the restored Dirlist.txt file (Line Input #1, strLineData)
* for each strLineData, you will need to inspect the data in different columns and issue a Name statement to rename the files whose names have been shortened.
Open "dirlist.txt" for Input as #1
Do Until EOF(#1)

  Line Input #1, strLine

  strShort = mid(strLine, 40, 12)
  strLong = mid(strLine, 56)

  If IsDate(mid(strLine, 1, 12)) And (Len(strShort) <> 0) Then
     Name strShort As strLong
  End If


Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

  strShort = trim(mid(strLine, 40, 12))
asgarcymedAuthor Commented:
aikimark - could you please post the whole vbs script (complete) ? I am a beginner yet; posting the whole vbs script would be more efficient to my learning... Thanks

That is as much of the script as I'm prepared to post at this time.  You must make some effort as as beginner to look at the statements I've used in my example and comments and at least read some help about their function and syntax.  Unless you put some effort into the learning experience, you will learn very little.

Pardon me if I'm interpreting your comment incorrectly, but I think the 'efficiency' you mention is me doing all your work for you.  I will gladly hold your hand, but I'm not going to write this application for you unless you are going to pay me to do that.  Otherwise, you might place a request for a backup/restore VB utility on RentACoder.com
asgarcymedAuthor Commented:
aikimark - You already helped me, so I must thank you and you deserve at least splitted points (it depends on other's eventual participation). However I disagree with you in the idea that posting all code has no additional value to my learning. For example, you can give a look at http://www.experts-exchange.com/Programming/Q_21812622.html you will see that someone (Idle_Mind) had the kindness of posting the whole vbs script. The advantage is that I can see all the instructions and try to understand line by line, and I can change some parameters and see the different results. Well, I must respect your position and thank you for the help you already gave me, but I would like that you or somebody else post the whole vbs script...

The 'entire code' depends on what decisions your application performs about source and target locations, patterns of files to copy, command line parameters, etc.

The example code I've supplied will rename files by reading the contents of the dirlist.txt file created before you did the backup and renaming files as necessary.

Why don't you start your understanding of VBscripting by examining the code sample I've supplied and ask me questions after looking at your online help source documentation.

Hint: also look at the Shell function.  What does it do?
asgarcymedAuthor Commented:
aikimark - What you suggest is much better than nothing, it is really a help, but could be even better if it was the entire code (and as you say there are many hypothesis, so the best thing to learn would be seeing the entire code of each hypothesis). I insist in this because I feel it is really important to me. Another example - Linux is the paradise of open-source, and that really helps to learn to program...
I am now studying better the sample code you post and the Shell function, but I would do it equally if I saw the entire code... It would be like an exercise with solutions to control the quality of my learning...
asgarcymedAuthor Commented:
My two goals with this question - backup and restore long file names, and learn VBS - are equally important... I need to solve this question quickly because I have 20 GB of files/folders that need to be renamed before being burned to DVD... I can zip but it will take a long time (20 GB !)...
<<My two goals with this question - backup and restore long file names, and learn VBS - are equally important>>

learning VBS is not part of your original question.  Please keep that goal away from this discussion.  It's not likely to happen in this discussion thread.  If you want to learn VBS, the start a new question about learning VBS.  

<<... I need to solve this question quickly because I have 20 GB of files/folders that need to be renamed before being burned to DVD...>>

1. Why rename them before you burn them?

2. Why reinvent this kind of software? (whatever it is)  There are plenty of applications that copy/restore files to optical media quite well (Roxio, Creative).

3. What is your rush?  What aren't you telling us about this project?

<< I can zip but it will take a long time (20 GB !)...>>

4. 20GB is larger than the capacity of most CDs/DVDs, so you can't copy this amount of data to a single disk without compression.  Compression is not part of the VBS language, so the complexity of this problem has just grown considerably.  If you can zip, then what makes you think that copying more data to the CD/DVD will be quicker than a single file?  Besides, in order to write to these devices, they need to be mounted differently than simply reading them.  In most cases, copying software sends specific, low level, commands to the CD/DVD drive.

5. This seems like much more than a 'learning exercise" from your recent comments.
asgarcymedAuthor Commented:
aikimark - I will comment your comments across the following 5 points :
1) I agree that learning VBS was not part of my original question. This is concomitant with the idea of asking the entire code. However, since a script is interpreted rather than compiled, I always can see the source-code, modify it, and learn with it. Again, this is also concomitant with the idea of asking the entire code.

2) Why rename files/folders before I burn them? Simply because ISO and UDF File Systems do not support as much characters as NTFS. I have 20 GB of files/folders that are in my HDD which has NTFS.

3) There is no software able to do what I want - backup/restore only the files/folders' long names, without creating zip files or other thing like that. I would spend too much time using a classical backup or compression application, when I want to be rapid (no compression, no backup file which takes a lot of time to be created and restored).

4) It is obvious that 20GB is larger than the capacity of all CDs/DVDs; I must burn 5 different DVD's (5 x 4.4 GB). If I try to burn the files/folders directly, the burner says "Error - file names is too long / path is too long". But if they were renamed it would be direct and rapid.

5) I think this question is not so difficult as you think... You are renitent in posting the entire vbs code, this is the key point; that is all I asked for... In other questions I have asked for other vbs scripts and someone have posted it promptly with no objections. Maybe we are misunderstanding each other... But try not to forget that this question is worth  500 Points, the maximum that is possible... As I have told you already helped me, so I must thank you and you deserve at least splitted points (it depends on other's eventual participation). Please do not be upset with me because I am well-intentionated...

2 (redux) Why reinvent the wheel?  Please read the very nicely written tutorial (with screenshots) of the Backup/Restore utility that comes with your operating system.  If you've mounted your optical media as a writable device.

3 (redux) you obviously haven't looked very hard.  check out RoboCopy that comes one the Windows resource kit.  Also, do a reasonable search.


4 (redux). As I've already stated, optical media don't record data nearly as fast as hard drives, so you would be many times better off if you included compression with your backups.  Moreover, you might be able to avoid a change of media if compression allows all 20GB to fit onto a single 4-7GB DVD platter.  I/O is the performance limiter here.  Compression takes place in memory and is orders of magnitude faster than I/O.

5 (redux). Implementing this backup/restore utility entirely with VBS is, IMHO, silly.  VBS can certainly be used to launch a specialized backup utility, but isn't optimized to do what you ask.  If you get other EE experts to participate in this thread, they might disagree with me.  Until then, please understand that I'm bringing almost 30 years of experience in this field into these discussions.

I've posted 90% of the code to do a rename.  In this case, you want to do a rename of all directory names and file names in the tree.  The code I posted was meant to be run after you restored the files.  You now say that the backup fails if long filenames are used.  That is new information that would have been helpful in your original question.

6. If you rename (hundreds/thousands of) directories and files on your hard drive prior to this backup, you may have great difficulty finding things while the backup is running.  Applications may fail as a result of path differences.  If you happen to rename a system file, REALLY BAD things could happen.  This isn't for the feint of heart (or rookies)

7.  If something goes wrong with code, you will be in deep water.  Remember that you are a beginner.  Since you are a rookie, I'm going to keep this as simple as I can and avoid using the FileSystemObject or WinScriptHost objects.  You are not ready to learn that.  Here is what I might suggest:
  * make a backup copy of the 20GB tree somewhere else on your hard drive.  NEVER PLAY WITH LIVE DATA
  * get a list of the directory names in the tree, starting with the top (root) directory where you want to start copying (renaming).
  * process each directory with VBS code in a bottom-up fashion, renaming the files and (then) directories as you climb.  This will involve finding the depth of each directory (number of "\" characters) and making multiple passes of the list.  There will probably be some array or collection processing.
  * pray that nothing goes wrong

8. What is your IT background?  Just starting work as a network admin? Student?  Hacker?

9. What is the scope of this project and your urgency?
asgarcymedAuthor Commented:
aikimark - I need such VBS Script because I download a lot of files from eMule, where file's names are really giant and now I do not have time enough to rename them manually, one-by-one. My urgency is that I must keep my downloaded files in DVD's because my HDD's space is almost full.
My IT background is a little bit of all hypothesis you asked - I administrate my home network which has 6 computers, I am a student of Informatics Engineering, and I try to be a "white hat hacker" (NOT a "black hat hacker" !!).
I decided to keep this question opened hoping that somebody do what I asked - a "magic" VBS script to backup and restore ONLY long file NAMES (not to backup/restore the files themselves). What I want is NOT a traditional backup/restore utility, ONLY NAMES should be backuped. I am sure that VBS can do that, however I do not know how to do it because I am a beginner in VBS yet. To clarify the ideas look at LONGSAVE from http://www.ctyme.com/download.htm - this  application seems to be good but does not work in NTFS (my HDD has NTFS so it is bad to me).
Have you tried
XCOPY *.* /N /S

The /N flag copies files with their short names.

This now makes very little sense.
10. backing up long filenames doesn't involve 20GB
11. if you copy a file to the CD/DVD, it still resides on your hard drive.
12. I guess you could open the file for output and close it which would set the end of file marker, rendering the file practically empty.  The directory entry would still exist with a long filename.  (there are hints to what can be done with the words I've used in this sentence)
13. wouldn't it be easier to get another hard drive?
14. wouldn't it be better to just limit your file sharing to the HDD space you can afford to use.  Sounds like you have overextended your capacity.
15. The DIR /X /S command that I mentioned earlier lists all files and directories and their short names.  There's your longname (only) backup.
asgarcymedAuthor Commented:
aikimark :

*) You are almost correct when you say that I am in the limits of my capacity. At present I have no money enough to buy a new HDD, and I have a friend which works at DVD's industry, so he can give me a great discount when buying DVD's. Thus, what I do is : download from eMule until my HDD is almost full => burn the eMule's dowloads in many DVD's => delete the files from my HDD => begin this cycle again. In future I will have money to buy a giant HDD (maybe a server) but until such moment happens (may take two years), I am forced to store data in DVD's. So you may understand better my question : download from eMule until my HDD is almost full => backup long files/folders' names (only names) => create a text file which stores the long names and the new equivalent  short names (example : "aaaaaaaaaaaaaaaaa" = "aaa"), renaming long names to short names => burn DVD's avoiding the errors "filename/path too long" => delete data from HDD after burning => later, copy everything from DVD's to my new HDD => restore long names from short names, automatically reading the text files which stores the equivalents between short and long name for each file ("aaaaaaaaaaaaaaaaa" = "aaa").

*) The « DIR /X /S >names.txt » command creates a text files (names.txt) which stores the equivalence/correspondence between short and long name for each file; what is exactly what I need... But how can I to restore long names from short names, automatically reading the names.txt file ?

*) The « XCOPY *.* /N /S » command seems to make no sense because it needs more disk space; spends many time copying; and, again, how can I automatically to restore long names from short names ?

Thank you for being patient and persistent trying to help me !
I've already shown you code to rename short files as long file names (within a directory.  have you at least tried that to see if it works for you?

16. I'm not sure what you mean by "XCOPY...needs more disk space..."

17. you still aren't making any sense to me when you state that you want to backup only the long file names.  In the same paragraph, you talk about copying files (which is different than copying names)

18. cut down on you eMule activity.  this problem was created by you and is being exacerbated by you.  STOP IT.
asgarcymedAuthor Commented:
aikimark - Go to « http://rapidshare.de/files/18774393/Long-Short_Names.exe.html » and download Long-Short_Names.exe => you will see exactly what I want! Finally a friend made it to me... However it crashes sometimes, so I would like to have a second (alternative) way of doing that.
A. I don't download and execute files from strangers
B. I advise everyone I know to avoid it
C. That includes file-sharing software
D. If you have a problem with the code your 'friend' made, then take it up with your friend or post the source code.
E. Realize your culpability in this situation.
F. If there is backup software that burns files to CD/DVD and preserves long file names, THEN USE IT.  Some software is normally packed with your hardware.  If not, then download something (commercial -- meant NERO earlier instead of ROXIO, shareware, freeware) or purchase it.  Please don't ask us to reinvent that wheel.  Take some portion of the money you've saved by getting a cheap/free DVD drive and disks and spend it on some software that will ease your pain ($20-$40)


G. In the future, when you ask a question and are given some code and advice, please don't reject either.  In this case, I'll share a sentiment originated by my business partner, "I'm afraid you aren't prepared for what we have to offer."  It isn't your lack of VBScript experience and batch file experience, but your lack of trying what I've suggested (or engaging me about what I've suggested) that has caused this impasse.  With many of my professional years spent as a software instructor, I can only urge you to just try it or question it.  Sitting there, waiting to be spoon-fed an answer won't work, since you won't learn anything in the process.  (and learning was one of the things you wanted out of this experience, right?)  We spoon-feed babies and only those adults incapable of feeding themselves.  I'm not putting you in either of those categories, nor will I enter into such a relationship if I can help it.

As far as learning VB, please consider the following sites, resources and books:

Excellent resource thread for newbies:



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
asgarcymedAuthor Commented:
aikimark - thanks for all your patience and persistence !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.