copy files and rename

A

ans

I need to copy files and rename the files.
The function below works ut it does not rename the copied files.


Function copyrename()
On Error Resume Next
MkDir "C:\copyrenamed"
Dim rs As DAO.Recordset
Dim strFileName As String
Dim strTargetFolder As String
strTargetFolder = "C:\copyrenamed\"
Set rs = CurrentDb.OpenRecordset("mypic")
' the table have the full path and name of the files I WANT TO COPY
' THE PATH of the file, and the filename (strfilename)
' the same table also has the description and I want the copied file to
' be called smth. like holiday2004_12345.png, easter2003_34567.bmp depending
of their decription
'
' this function only copy the file 12345.png to the new directory
'without renaming it
'
With rs
Do Until .EOF
strFileName = Dir(!path)
If Len(strFileName) = 0 Then
MsgBox "The file '" & !path & "' is not there!!"
Else
FileCopy !path, strTargetFolder & strFileName
End If
.MoveNext
Loop
.Close
End With
Set rs = Nothing
MsgBox "Done!"
End Function
 
K

Ken Snell

Include the Name .. As statement after you do the FileCopy step:

Name strTargetFolder & strFileName As strTargetFolder & "NewFileName"
 
D

Douglas J. Steele

I'm surprised you're getting anything copied, since you're only giving a
folder (with no wildcards) in your FileCopy statement.

FileCopy !path, strTargetFolder & strFileName

Assuming you have some way of automatically calculating what the new file
name should be, try

FileCopy !path & strFileName, strTargetFolder & strNewFileName
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top