Solved

Bulk rename files to Win95 format

Posted on 2004-08-13
14
236 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 19

Accepted Solution

by:
Shauli earned 250 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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now