Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Bulk rename files to Win95 format

Posted on 2004-08-13
14
Medium Priority
?
244 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
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.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

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…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

597 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