Changing Files Names

Hemish

Registered User.
Local time
Today, 01:03
Joined
Jan 20, 2005
Messages
65
Hi does anyone know in how in Access 2000 using VBA, how I can change the name filenames. I have over 100 pictures.

I have a table in Access with the old filenames of the pictures and another field with the new names.
Eg
Old Name New Name
Test Test05

Is there anyway to do this in code.

Thankyou
 
Hello,

The code below copies files, and then deletes the original which effectively does what you require. You just need to pull in the information from your table, probably by setting it as a recordset and then pass the names over as variables.

Dim strFileOldName, strFileNewName As String
strFileOldName = "C:\Documents and Settings\szymkm\My Documents\CBA_Data_Master_Cross.pdf"
strFileNewName = "C:\Documents and Settings\szymkm\My Documents\" & CICODE & ".pdf"

FileCopy strFileOldName, strFileNewName
Kill strFileOldName

I hope this helps you.

Thanks

Mark
 
Hi Thanks for the piece of code i will try it and let you know
 
You can use the NAME function. This File I/O function performs file renaming and moving.
Code:
Name "C:\folder\file.txt" As "C:\folder\newname.txt"

Changing the destination of the second filename will perform the move/rename at the same time.
 
I use this to rename an output file:
Code:
Sub RenameFile(PTH As String, FN1 As String, FN2 As String)
Dim fso, f, P1
Set fso = CreateObject("Scripting.FileSystemObject")
If Right(PTH, 1) <> "\" Then
  P1 = PTH & "\"
Else
  P1 = PTH
End If
' Check if file exists (to rename to)
If fso.FileExists(P1 & FN2) Then
  ' Delete if not read only
  fso.DeleteFile P1 & FN2, False
End If
Set f = fso.GetFile(P1 & FN1)
f.Name = FN2
Set f = Nothing
Set fso = Nothing
End Sub
 

Users who are viewing this thread

Back
Top Bottom