?
Solved

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

Posted on 2006-04-21
20
Medium Priority
?
771 Views
Last Modified: 2012-08-14
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.
0
Comment
Question by:asgarcymed
  • 10
  • 10
20 Comments
 
LVL 46

Expert Comment

by:aikimark
ID: 16506316
* 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.
0
 

Author Comment

by:asgarcymed
ID: 16509542
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).
0
 
LVL 46

Expert Comment

by:aikimark
ID: 16510563
* 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.
Example:
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

Loop

Close
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 46

Expert Comment

by:aikimark
ID: 16510702
Correction:
  strShort = trim(mid(strLine, 40, 12))
0
 

Author Comment

by:asgarcymed
ID: 16511744
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
0
 
LVL 46

Expert Comment

by:aikimark
ID: 16511904
@asgarcymed

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
0
 

Author Comment

by:asgarcymed
ID: 16512143
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...
0
 
LVL 46

Expert Comment

by:aikimark
ID: 16512601
@asgarcymed

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?
0
 

Author Comment

by:asgarcymed
ID: 16514160
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...
0
 

Author Comment

by:asgarcymed
ID: 16514319
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 !)...
0
 
LVL 46

Expert Comment

by:aikimark
ID: 16515010
<<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.
0
 

Author Comment

by:asgarcymed
ID: 16515135
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...

Greetings
0
 
LVL 46

Expert Comment

by:aikimark
ID: 16516239
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.
http://uis.georgetown.edu/software/documentation/win2000/win2000.backup.open.html

3 (redux) you obviously haven't looked very hard.  check out RoboCopy that comes one the Windows resource kit.  Also, do a reasonable search.
http://www.thefreecountry.com/utilities/backupandimage.shtml
http://www.freebyte.com/filediskutils/#backup

http://labmice.techtarget.com/Utilities/backup.htm
http://www.sharewarejunkies.com/win_backup.htm
http://www.tucows.com/search?search_terms=backup&search_scope=win&search_adv=0&search_size=&search_size_multi=b
http://reviews-zdnet.com.com/4566-3682_16-0.html

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?
0
 

Author Comment

by:asgarcymed
ID: 16517110
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).
0
 
LVL 46

Expert Comment

by:aikimark
ID: 16517318
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.
0
 

Author Comment

by:asgarcymed
ID: 16519697
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 !
0
 
LVL 46

Expert Comment

by:aikimark
ID: 16520732
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.
0
 

Author Comment

by:asgarcymed
ID: 16520894
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.
0
 
LVL 46

Accepted Solution

by:
aikimark earned 1000 total points
ID: 16521959
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)

http://www.argentuma.com/backup/software/dla.html
http://www.ntius.com/default.asp?p=cdmaker/filecd3_main
http://www.argentuma.com/backup/software/winbackup.html
http://www.argentuma.com/backup/software/backup-now.html
http://www.argentuma.com/backup/software/incd.html
http://www.sharewareconnection.com/lfnit-.htm
http://www.sharewareconnection.com/zip-backup-to-cd.htm

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:
http://visualbasic.about.com/od/learnvbscript/ss/vbsadmin.htm
http://www.w3schools.com/vbscript/default.asp
http://www.trainingtools.com/online/vbscript/index.htm
http://www.youlearn.com/products/lk-products/V/vba5/vba5.html
http://visualbasic.about.com/od/learnvbscript/l/bllvbscripta.htm
http://visualbasic.about.com/od/learnvbscript/
http://www.functionx.com/vbscript/
http://www.computerperformance.co.uk/vbscript/wmi_basics.htm
http://www.microsoft.com/technet/scriptcenter
http://www.microsoft.com/technet/scriptcenter/guide/sas_pt1_overview.mspx?mfr=true

Excellent resource thread for newbies:
http://groups.google.com/groups?hl=en&th=7015b808b5fb0cb4

http://www.vbwm.com/learnvb/

http://www.amazon.com/gp/product/1565922476/102-0851678-3124921?v=glance&n=283155
http://www.windowsitlibrary.com/BookReviews/BookReview.cfm?BookReviewID=86
0
 

Author Comment

by:asgarcymed
ID: 16522846
aikimark - thanks for all your patience and persistence !
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month17 days, 9 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question