PDA

View Full Version : Solved: Change the complicated names of the files in a folder as regular (1 - 2 - 3 ... n )



Erdin? E. Ka
10-12-2006, 02:17 PM
Hi there, :hi:

I want to make regular (1 - 2 - 3 ... n ) name the files in a folder which files are ".bmp" surnamed instead of the complicated names.

For example:

The folder is:
C:\Pictures

The Files of this Directory:
ASAD.bmp
WER.bmp
SDLS.bmp
TEE.xls
FDFDL.doc
DPFDP.bmp
GKFLLF.jpg
LAST.bmp

My wish is;
Give new names only to .bmp surnamed files with a VBA code.

After code is running;

instead of ASAD.bmp : 1.bpm
instead of WER.bmp : 2.bpm
instead of SDLS.bmp : 3.bpm
TEE.xls : No changing
FDFDL.doc : No changing
instead of DPFDP.bmp : 4.bpm
GKFLLF.jpg : No changing
instead of LAST.bmp : 5.bpm

:banghead: I tried some different ways to do it but i couldn't. :dunno

Thanks a lot. :think:

Bob Phillips
10-12-2006, 02:25 PM
Sub LoopFolders()
Dim oFSO As Object
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim i As Long
Dim sPath As String


Set oFSO = CreateObject("Scripting.FileSystemObject")

sPath = "C:\Pictures"

Set Folder = oFSO.GetFolder(sPath)

For Each file In Folder.Files
If file.Type = "Bitmap Image" Then
MsgBox file.Path
i = i + 1
Name file.Path As Replace(file.Path, file.Name, i & ".bmp")
End If
Next file

Set oFSO = Nothing

End Sub

mdmackillop
10-12-2006, 02:33 PM
Option Explicit
Sub ReNames()
Dim MyPath As String, MyName As String, i As Long
MyPath = "C:\Pictures\"
MyName = Dir(MyPath)
Do While MyName <> ""
If UCase(Right(MyName, 3)) = "BMP" Then
i = i + 1
Name MyPath & MyName As MyPath & i & ".bmp"
End If
MyName = Dir
Loop
End Sub

malik641
10-12-2006, 03:03 PM
Option Explicit
Option Compare Text

Sub ChangeBMP()
Dim path As String
Dim i As Long
path = "C:\Pictures\"

With Application.FileSearch
.NewSearch
.LookIn = path
.Filename = "*.bmp"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Name CStr(.FoundFiles(i)) As path & i & ".bmp"
Next
End If
End With
End Sub
:)

Erdin? E. Ka
10-12-2006, 03:04 PM
:p
Soo fast solutions.!

I wanted just only one "eye" from God, God gave me three eyes!! :rotlaugh:

Thank you very much mdmackillop and xld and malik641, these are perfect. :friends:

malik641
10-12-2006, 03:07 PM
thank you very much msmackillop and malik641, these are perceft. :friends:
Well, I didn't know Ms. mackillop was writing your code for you :rotlaugh:


and no problem :thumb

BTW, I noticed you changed it....that's okay...it's still funny to me :giggle

malik641
10-12-2006, 03:15 PM
Hey Bob,

When it comes to file manipulation I've noticed you seem to like to use the FileSystemObject approach...so why do you use the Name file As new_name method when you could use the .Move or .MoveFile methods?

Just wondering :)

Erdin? E. Ka
10-12-2006, 03:17 PM
Well, I didn't know Ms. mackillop was writing your code for you :rotlaugh:


and no problem :thumb

BTW, I noticed you changed it....that's okay...it's still funny to me :giggle


Excuse me, i wrote quickly and did it wrong.

:dunno :*) :mkay

Bob Phillips
10-12-2006, 04:10 PM
Hey Bob,

When it comes to file manipulation I've noticed you seem to like to use the FileSystemObject approach...so why do you use the Name file As new_name method when you could use the .Move or .MoveFile methods?

Just wondering :)

I use FSO because both FileSearch and Dir are flawed, but when I can use pur VB I do.

malik641
10-12-2006, 05:21 PM
I use FSO because both FileSearch and Dir are flawed, but when I can use pur VB I do.I see.



Just when I liked my solution too :giggle

Erdin? E. Ka
10-12-2006, 06:49 PM
...I wanted just only one "eye" from God, God gave me three eyes!...

Just a little correction:

It's a Turkish Proverb:
The blindman wished just only 1 eye from God, then God gave him 3 eyes.

Thanks again to kindly helps. See you.:hi: