Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, Simple question...I hope. I 1

Status
Not open for further replies.

nayfeh

Programmer
Mar 13, 2002
163
CA
Hi,

Simple question...I hope. I have a function below that's used to copy data to a file if a file exists, otherwise it creates it. I now need to delete the file from the source location once the copy/create has completed. Only if it successfully copied.

Here's the function:

Sub AppendToFile(SourceName As String, DestName As String)
Dim SourceHandle As Integer
SourceHandle = FreeFile
Open SourceName For Input As #SourceHandle

Dim DestHandle As Integer
DestHandle = FreeFile
Open DestName For Append As #DestHandle

Do While Not EOF(SourceHandle)
Dim SomeText As String
Line Input #SourceHandle, SomeText
Print #DestHandle, SomeText
Loop

Close #SourceHandle
Close #DestHandle
End Sub

Thanks so much for your help!
TN
 
If you just want to check for the existence of the destination file, you could do something like this:

if dir(destname)<>&quot;&quot; then kill sourcename


if the destination file is there, but not updated, you'd have to check the file date / time attribute of both source and destination, then delete the source file if they're the same:

if dir(destname)<>&quot;&quot; then
if fildatetime(sourcename)=filedatetime(destname) then
kill sourcename
end if
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top