Thanks,
Dan
On 18.03.2010 11:10, Dan wrote:
> How can I make a copy of C:\Source\test.txt to C:\CopyLoc\
> but if test.txt already exist in C:\CopyLoc\ not to do anything.
Use this Win32 API function:
Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" ( _
ByVal AExistingFileName As String, _
ByVal ANewFileName As String, _
ByVal AFailIfExists As Boolean _
) As Boolean
Copy it in a standard module and simply use it as:
CopyFile "C:\Source\test.txt", "C:\CopyLoc\test.txt", True
mfG
--> stefan <--
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("C:\CopyLoc\text.txt") Then
msgbox "Test.txt already present in c:\copyloc"
else
fs.copyfile "C:\Source\test.txt" "c:\copyloc\"
End If
set fs=nothing
this is another way to do the same
if dir("c:\copyloc\test.txt")="" then ''the file doesn't exist in c:\copyloc
filecopy "C:\Source\test.txt" "c:\copyloc\test.txt"
endif
all this is aircode
HTH Paolo
On 18.03.2010 11:45, Paolo wrote:
> this is one way
> this is another way to do the same
Not really, both solutions have the same problem: Timing.
Right after checking for the non-existence of the file any other process
may create this file. Then your FileCopy will still fail.
mfG
--> stefan <--
http://www.devhut.net/index.php?lang=en&pid=0000000027#CopyFile
--
Hope this helps,
Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
"Stefan Hoffmann" wrote:
> .
>
On the other hand, the FileSystemObject.CopyFile method does have an
<overwrite> argument that can be specified as False to prevent overwriting
an existing file. If you try, an error will be raised, that one would
presumably want to trap in the code.
--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html
(please reply to the newsgroup)