View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Excel help - Find and copy files


1) Does the spreadsheet have the TIF on the end of the file?
If it does make the modifications below. Also check carefully that the file
names in the spreadsheet matches the files in the directory.

2) Does the filenames on the spreadsheet contain the folder and the
filename? If so I need to make additional changes.

Note: The Folder names must be corrrect otherwise excel would give the Error
PATH not found.


Sub copyfiles()

OldFolder = "c:\temp\"
NewFolder = "c:\temp\test\"

With Sheets("Sheet1")
RowCount = 1
Do While .Range("A" & RowCount) < ""
FName = .Range("A" & RowCount)
FileCopy Source:=OldFolder & FName, _
Destination:=NewFolder & FName
RowCount = RowCount + 1
Loop
End With
End Sub




"Ikenest" wrote:

Thanks Joel!

Thanks for your prompt response. I keep getting prompted with the Message
("Could Not find file : " & FName) and no file is copied to the "Backup
Folder".

Sincerely,
--
Nestor Ike


"Joel" wrote:

I added a test to make sure the file existed.


OldFolder = "G:\LMG\RECOVERY\AGENCY\Portfolio Sale\2008\A-Program2 Sale
Files\Imaged Copies\Disk1\Disk 1\"
NewFolder = "G:\LMG\RECOVERY\AGENCY\Portfolio Sale\2008\A-Program2 Sale
Files\Imaged Copies\BackUp\"

With Sheets("All")
RowCount = 1
Do While .Range("A" & RowCount) < ""
FName = .Range("A" & RowCount)
CheckName = Dir(OldFolder & FName & ".tif")
if CheckName < "" then
FileCopy Source:=OldFolder & FName & ".tif", _
Destination:=NewFolder & FName & ".tif"
Else
MsgBox("Could Not find file : " & FName)
End iF
RowCount = RowCount + 1
Loop
End With
End Sub


"Ikenest" wrote:

Hi Joel,

Thanks for looking into this. I tried and used your code, but I get an error
message (Run-time error '53': File not found). The filenames on the excel
document only contain tif extension. So I am trying to copy and move files
which filenames match ONLY the filenames in my excel document from the files'
directory to a new directory. See below

Sub copyfiles()

OldFolder = "G:\LMG\RECOVERY\AGENCY\Portfolio Sale\2008\A-Program2 Sale
Files\Imaged Copies\Disk1\Disk 1\"
NewFolder = "G:\LMG\RECOVERY\AGENCY\Portfolio Sale\2008\A-Program2 Sale
Files\Imaged Copies\BackUp\"

With Sheets("All")
RowCount = 1
Do While .Range("A" & RowCount) < ""
FName = .Range("A" & RowCount)
FileCopy Source:=OldFolder & FName & ".tif", _
Destination:=NewFolder & FName & ".tif"
RowCount = RowCount + 1
Loop
End With
End Sub







--
Nestor Ike


"Joel" wrote:

The code will look something like the code below. I don't know if the
filenames on the spreadsheet contain the directory or the tif extension.
Modify the code as necessary. Change OldFolder and NewFolder as required.


Sub copyfiles()

OldFolder = "c:\temp\"
NewFolder = "c:\temp\test\"

With Sheets("Sheet1")
RowCount = 1
Do While .Range("A" & RowCount) < ""
FName = .Range("A" & RowCount)
FileCopy Source:=OldFolder & FName & ".tif", _
Destination:=NewFolder & FName & ".tif"
RowCount = RowCount + 1
Loop
End With
End Sub


"Ikenest" wrote:

I need to find file names - from a list in an excel file - that match file
names (with an extension, i.e., 1466319001_20080923193500.tif) located in one
directory folder and save the matched files to a different directory folder.

Thanks,

--
Nestor Ike