?
Solved

Bulk rename files to Win95 format

Posted on 2004-08-13
14
Medium Priority
?
243 Views
Last Modified: 2010-05-02
Hi,

I need to bulk rename a large amound of files held in various sub directories to 42 char length (including 3 char extension)

Can anyone suggest some quick code to do that for me?

Thanks in advance
Matt
0
Comment
Question by:razorhazor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
14 Comments
 
LVL 19

Expert Comment

by:Shauli
ID: 11795470
As far as I recall, win95 format is 8 characters and extension, not 42, so what are you after, renaming to 8 characters length or to 42 characters length?

S
0
 

Author Comment

by:razorhazor
ID: 11795506
42 characters ala xbox FATX
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11795549
OK :), any particular way you want to rename to? How do you want the renamed file to look like? can you post an example of a current filename and the desired renamed filename?

S
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:razorhazor
ID: 11795589
if they could just be renamed to say the first 39 chars of the existing filename that would be cool.
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11795660
So its 42 including extension, which will make it 38 plus dot plus three extension. If that is correct then give me 10, otherwise, stop me right away  :)

S
0
 
LVL 19

Accepted Solution

by:
Shauli earned 1000 total points
ID: 11795820
Try this:

'where you want to execute.
Private Sub Command1_Click()
Call RenameForXbox("C:\myFolder\mySubFolder\")
End Sub


Public Sub RenameForXbox(ByVal sbPath As String)
Dim myFileName As String
                myFileName = Dir(sbPath, vbDirectory)
                Do While Not myFileName = vbNullString
                    Select Case myFileName
                        Case ".", ".."
                        Case Else
                            If Len(myFileName) >= 38 Then
                                'if filename is equal to or greater then 38 characters
                                Name myFileName As Left(myFileName, 38) & Right(myFileName, 4)
                            Else
                                'if filename is shorter then 38 characters
                                Name sbPath & myFileName As sbPath & Left(myFileName, Len(myFileName) - 4) & Right(myFileName, 4)
                            End If
                    End Select
                    myFileName = Dir
                Loop

End Sub

S

0
 
LVL 19

Expert Comment

by:Shauli
ID: 11795836
ps. Make sure you have a backup before you test it, though :)

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11796533
Ops, one correction, it might affect those filenames which are exactly 38 length, so

change this line

 If Len(myFileName) >= 38 Then

To be this line

 If Len(myFileName) >= 42 Then
'                                  ^^

S
0
 

Author Comment

by:razorhazor
ID: 11797195
cool, cheers mate, will that do sub dirs automatically? thats what I really need.

Cheers man!
Matt
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11797226
No. You'll have to call it for each folder or subfolder, or you can do:

Private Sub Command1_Click()
Call RenameForXbox("C:\myFolder1\mySubFolder1\")
Call RenameForXbox("C:\myFolder1\mySubFolder2\")
Call RenameForXbox("C:\myFolder1\mySubFolder3\")
Call RenameForXbox("C:\myFolder2\mySubFolder1\")
Call RenameForXbox("C:\myFolder2\mySubFolder2\")
'etc etc etc...
End Sub

S
0
 
LVL 7

Assisted Solution

by:Burbble
Burbble earned 1000 total points
ID: 11800263
Here's a recursive function that you can use to access files in subdirectories:

-----

Dim AllFolders As New Collection

Private Sub GetSubFolders(ByVal Directory As String)
    Dim FSO, tmpGet, tmpSub, tmpFolder
    Dim CurrentFolders As New Collection

    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set tmpGet = FSO.GetFolder(Directory)
    Set tmpSub = tmpGet.SubFolders

    For Each tmpFolder In tmpSub
        If Right$(Directory, 1) = "\" Then
            AllFolders.Add Directory & tmpFolder.Name
            CurrentFolders.Add Directory & tmpFolder.Name
        Else
            AllFolders.Add Directory & "\" & tmpFolder.Name
            CurrentFolders.Add Directory & "\" & tmpFolder.Name
        End If
    Next

    For Each tmpFolder In CurrentFolders
        GetSubFolders (tmpFolder)
    Next
End Sub

Private Sub GetFiles(ByVal Directory As String)
    Dim FSO, tmpGet, tmpSub, tmpFile
    Dim CurrentFiles As New Collection

    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set tmpGet = FSO.GetFolder(Directory)
    Set tmpSub = tmpGet.Files

    For Each tmpFile In tmpSub
        processfile (tmpFile) 'Use your function here, this is the loop for each file
    Next
End Sub

Private Sub Form_Load()
    Dim tmpFolder

    GetSubFolders ("C:\My Music") 'Change this path to whatever you need

    For Each tmpFolder In AllFolders
        GetFiles tmpFolder
    Next
End Sub

-----

-Burbble
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

765 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