Solved

Bulk rename files to Win95 format

Posted on 2004-08-13
14
235 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
Comment Utility
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
Comment Utility
42 characters ala xbox FATX
0
 
LVL 19

Expert Comment

by:Shauli
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 19

Accepted Solution

by:
Shauli earned 250 total points
Comment Utility
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
Comment Utility
ps. Make sure you have a backup before you test it, though :)

S
0
 
LVL 19

Expert Comment

by:Shauli
Comment Utility
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
Comment Utility
cool, cheers mate, will that do sub dirs automatically? thats what I really need.

Cheers man!
Matt
0
 
LVL 19

Expert Comment

by:Shauli
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

772 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

12 Experts available now in Live!

Get 1:1 Help Now