Search directory, copy and rename file

S

Sash

I have hundreds of CDs where I need to copy images from a directory on the CD
to a drive on my computer. The structure on the CD is always as listed below
where SNum is an internal number that changes. I currently have a form where
the person would key in the SNum and I'm trying to copy all TIF files from
that directory to D: and rename with the file name and SNum. Any suggestions
would be greatly appreciated. The following is returning nothing for the
strFileName.

Dim strPath, strFileName, strFullPath, strFile As String
strPath = "E:\" & Me!SNum & "\DATAGRP\" & Me!SNum & "\IMG1\"

strFileName = Dir(strPath & "*.tif")
strFile = Left(strFileName, 8)
Do While Len(strFileName) > 0
strFullPath = strPath & strFileName
FileCopy strFullPath, "D:\HIM\Images\" & strFile & Me!SNum &
".tif"
Loop
 
S

Steve Sanford

If you have a statement like this:
Dim strPath, strFileName, strFullPath, strFile As String

only strFile is a string. All the rest are Varients types.

Try this:

'----------------------- Dim strPath As String
Dim strFile As String
Dim strFileName As String
Dim SourceFile As String
Dim DestinationFile As String

strPath = "E:\" & Me!SNum & "\DATAGRP\" & Me!SNum & "\IMG1\"

'get the first file name
strFile = Dir(strPath & "*.tif")

Do While strFile <> ""
strFileName = Left(strFile, InStr(1, strFile, ".") - 1)
SourceFile = strPath & strFile
DestinationFile = "D:\HIM\Images\" & strFileName & Me!SNum & ".tif"

'copy the file
FileCopy SourceFile, DestinationFile

' Call Dir again without arguments to return the next file in the
' same directory.
strFile = Dir

Loop
'-------------------------------


HTH
 

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