Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel help - Find and copy files

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Excel help - Find and copy files

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel help - Find and copy files


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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Excel help - Find and copy files

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel help - Find and copy files


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



  #6   Report Post  
Posted to microsoft.public.excel.programming
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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel help - Find and copy files

1) Below is a sample filename in Sheet 'All', cell (A1) - on the spreadsheet:

1458600001_20080924094025.tif

2) No, the filenames on the spreadsheet only have the filename

Below is the sample of how files are lined up in the folder
(G:\LMG\RECOVERY\AGENCY\Portfolio Sale\2008\A-Program2 Sale Files\Imaged
Copies\Disk1\Disk 1)

In the folder:
Name
1458600001_20080924094025.tif

Size
1,324

Type
TIF File

Date Modified
9/24/2008 9:24 AM

Thanks a bunch for your assistance

--
Nestor Ike


"Joel" wrote:

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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel help - Find and copy files


THANKS A TON !!!!

It has worked perfectly, just like I wanted it to. YOU rock!!!!!!!!!!
--
Nestor Ike


"Ikenest" wrote:

1) Below is a sample filename in Sheet 'All', cell (A1) - on the spreadsheet:

1458600001_20080924094025.tif

2) No, the filenames on the spreadsheet only have the filename

Below is the sample of how files are lined up in the folder
(G:\LMG\RECOVERY\AGENCY\Portfolio Sale\2008\A-Program2 Sale Files\Imaged
Copies\Disk1\Disk 1)

In the folder:
Name
1458600001_20080924094025.tif

Size
1,324

Type
TIF File

Date Modified
9/24/2008 9:24 AM

Thanks a bunch for your assistance

--
Nestor Ike


"Joel" wrote:

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

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel help - Find and copy files

Joel,

One more question, it looks like all the files are being copied to the
NewFolder, regardless of being a match or not:

What I need to accomplish is to be able:

1) Find filenames from the open excel spreadsheet that match the files in
the OldFolder
2) Copy ONLY the matched file, NOT all files

I guess we are in the right direction.

Thanks again,

---
Nestor Ike


"Ikenest" wrote:

THANKS A TON !!!!

It has worked perfectly, just like I wanted it to. YOU rock!!!!!!!!!!
--
Nestor Ike


"Ikenest" wrote:

1) Below is a sample filename in Sheet 'All', cell (A1) - on the spreadsheet:

1458600001_20080924094025.tif

2) No, the filenames on the spreadsheet only have the filename

Below is the sample of how files are lined up in the folder
(G:\LMG\RECOVERY\AGENCY\Portfolio Sale\2008\A-Program2 Sale Files\Imaged
Copies\Disk1\Disk 1)

In the folder:
Name
1458600001_20080924094025.tif

Size
1,324

Type
TIF File

Date Modified
9/24/2008 9:24 AM

Thanks a bunch for your assistance

--
Nestor Ike


"Joel" wrote:

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

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Excel help - Find and copy files


The code gets the source filename from the spreadsheet so it will only copy
the files that exist in the spreadsheet. Try copying one of the files from
the source directory back into the source directory so you get Copy of
abc.tif. Then run the program again and see if you get the copy into the
destination directory.

"Ikenest" wrote:

Joel,

One more question, it looks like all the files are being copied to the
NewFolder, regardless of being a match or not:

What I need to accomplish is to be able:

1) Find filenames from the open excel spreadsheet that match the files in
the OldFolder
2) Copy ONLY the matched file, NOT all files

I guess we are in the right direction.

Thanks again,

---
Nestor Ike


"Ikenest" wrote:

THANKS A TON !!!!

It has worked perfectly, just like I wanted it to. YOU rock!!!!!!!!!!
--
Nestor Ike


"Ikenest" wrote:

1) Below is a sample filename in Sheet 'All', cell (A1) - on the spreadsheet:

1458600001_20080924094025.tif

2) No, the filenames on the spreadsheet only have the filename

Below is the sample of how files are lined up in the folder
(G:\LMG\RECOVERY\AGENCY\Portfolio Sale\2008\A-Program2 Sale Files\Imaged
Copies\Disk1\Disk 1)

In the folder:
Name
1458600001_20080924094025.tif

Size
1,324

Type
TIF File

Date Modified
9/24/2008 9:24 AM

Thanks a bunch for your assistance

--
Nestor Ike


"Joel" wrote:

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



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel help - Find and copy files

Hi Joel,

Sorry that I could not get to you sooner ... YOU ROCK!!! The files have
been copied as expected. Thanks for your patience and assistance in making
things easier for me
--
Nestor Ike


"Joel" wrote:

The code gets the source filename from the spreadsheet so it will only copy
the files that exist in the spreadsheet. Try copying one of the files from
the source directory back into the source directory so you get Copy of
abc.tif. Then run the program again and see if you get the copy into the
destination directory.

"Ikenest" wrote:

Joel,

One more question, it looks like all the files are being copied to the
NewFolder, regardless of being a match or not:

What I need to accomplish is to be able:

1) Find filenames from the open excel spreadsheet that match the files in
the OldFolder
2) Copy ONLY the matched file, NOT all files

I guess we are in the right direction.

Thanks again,

---
Nestor Ike


"Ikenest" wrote:

THANKS A TON !!!!

It has worked perfectly, just like I wanted it to. YOU rock!!!!!!!!!!
--
Nestor Ike


"Ikenest" wrote:

1) Below is a sample filename in Sheet 'All', cell (A1) - on the spreadsheet:

1458600001_20080924094025.tif

2) No, the filenames on the spreadsheet only have the filename

Below is the sample of how files are lined up in the folder
(G:\LMG\RECOVERY\AGENCY\Portfolio Sale\2008\A-Program2 Sale Files\Imaged
Copies\Disk1\Disk 1)

In the folder:
Name
1458600001_20080924094025.tif

Size
1,324

Type
TIF File

Date Modified
9/24/2008 9:24 AM

Thanks a bunch for your assistance

--
Nestor Ike


"Joel" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find & Copy Files Listed in Excel Worksheet ? bogdog Excel Programming 2 May 8th 08 04:40 PM
Excel 2003 SP3 - can't find the .cub files soppy_skyblue Excel Discussion (Misc queries) 2 January 3rd 08 01:01 AM
Excel can't find files bscra Excel Discussion (Misc queries) 2 October 21st 07 12:14 AM
open some txt files ,find text , copy the text before that to a single cell gus Excel Programming 2 July 11th 05 05:40 PM
find files and copy to new directory arne Excel Programming 3 November 26th 03 07:26 PM


All times are GMT +1. The time now is 05:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"