test if file exists

test if file exists

Anonymous
Not applicable
1,314 Views
6 Replies
Message 1 of 7

test if file exists

Anonymous
Not applicable
Hello AutoCAD VBA Users,

How do I test if a file exists? I have a For Loop that will open a DXF
file (e.g. concatenate the loop number to the filename to come up with
file1.dxf, file2.dxf, etc.), do some VBA changes, then save as DWG.
Problem is I get an error message when a file doesn't exist.

Thanks,

Jeff Jensen, [email protected]

Sent via Deja.com http://www.deja.com/
Before you buy.
0 Likes
Accepted solutions (1)
1,315 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Accepted solution
Hi!
You can check for presence of a file by using "DIR" function.
The function returns the file name if the file exists in the specified path
or else it returns a zero length string.

Check in VBA help for more information as you can do lot many things with
this function.

--
bye,

P.Murali
wrote in message
news:[email protected]...
> Hello AutoCAD VBA Users,
>
> How do I test if a file exists? I have a For Loop that will open a DXF
> file (e.g. concatenate the loop number to the filename to come up with
> file1.dxf, file2.dxf, etc.), do some VBA changes, then save as DWG.
> Problem is I get an error message when a file doesn't exist.
>
> Thanks,
>
> Jeff Jensen, [email protected]
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
0 Likes
Message 3 of 7

Anonymous
Not applicable
You can download ACADX.ARX from the customer-files
newsgroup, and use its 'FindFile()' method.

[email protected] wrote:
>
> Hello AutoCAD VBA Users,
>
> How do I test if a file exists? I have a For Loop that will open a DXF
> file (e.g. concatenate the loop number to the filename to come up with
> file1.dxf, file2.dxf, etc.), do some VBA changes, then save as DWG.
> Problem is I get an error message when a file doesn't exist.
>
> Thanks,
>
> Jeff Jensen, [email protected]
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

--
/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* [email protected] */
/* http://ourworld.compuserve.com/homepages/tonyt */
/*********************************************************/
0 Likes
Message 4 of 7

Anonymous
Not applicable
[email protected] wrote:

> Hello AutoCAD VBA Users,
>
> How do I test if a file exists? I have a For Loop that will open a DXF
> file (e.g. concatenate the loop number to the filename to come up with
> file1.dxf, file2.dxf, etc.), do some VBA changes, then save as DWG.
> Problem is I get an error message when a file doesn't exist.
>
> Thanks,
>
> Jeff Jensen, [email protected]
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

Another thing to try is to use error handling as well s the built in
findfiles and dir stuff.
eg
on error resume next
... do your stuff here ...say kill a file or attempt opening a file
.... and if this triggers an error you can now check it thus
if err.number<>0 then
..do whatever you need to do if an error ocurred etc
end if
0 Likes
Message 5 of 7

Anonymous
Not applicable
Check out the Dir() function. The online help is pretty clear.

[email protected] wrote:
>
> Hello AutoCAD VBA Users,
>
> How do I test if a file exists? I have a For Loop that will open a DXF
> file (e.g. concatenate the loop number to the filename to come up with
> file1.dxf, file2.dxf, etc.), do some VBA changes, then save as DWG.
> Problem is I get an error message when a file doesn't exist.
>
> Thanks,
>
> Jeff Jensen, [email protected]
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
0 Likes
Message 6 of 7

Anonymous
Not applicable
'Add this code to the appropriate event:

'success% = FileExists%("C:\vb\vb.exe") 'A full path and filename

' FileExists% returns True if file exists
'If success% = True Then
'MsgBox "This file already exists." ', 48, File Error
'Else
'MsgBox "No File Found"
'End If
'End Sub
'How to detect if a file already exists.
'-------------------------------------------------------------------
' To detect an existing file, use the function below:

'Function FileExists%(fname$)
'On Local Error Resume Next

'Dim ff%
' ff% = FreeFile
' Open fname$ For Input As ff%

' If Err Then
' FileExists% = False
' Else
' FileExists% = True
' End If

' Close ff%

'End Function

wrote in message
news:[email protected]...
> Hello AutoCAD VBA Users,
>
> How do I test if a file exists? I have a For Loop that will open a DXF
> file (e.g. concatenate the loop number to the filename to come up with
> file1.dxf, file2.dxf, etc.), do some VBA changes, then save as DWG.
> Problem is I get an error message when a file doesn't exist.
>
> Thanks,
>
> Jeff Jensen, [email protected]
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
0 Likes
Message 7 of 7

Anonymous
Not applicable
There is a simpler (and faster) way: use the Dir$ function. e.g.:
Dir$("c:\program files\mdt\acad.exe") will return "acad.exe" if the file
exists in that location or "" if it doesn't.

--
Visit me at: http://www2.stonemedia.com/franko

"Jim Arthur" wrote in message
news:[email protected]...
> 'Add this code to the appropriate event:
>
> 'success% = FileExists%("C:\vb\vb.exe") 'A full path and filename
>
> ' FileExists% returns True if file exists
> 'If success% = True Then
> 'MsgBox "This file already exists." ', 48, File Error
> 'Else
> 'MsgBox "No File Found"
> 'End If
> 'End Sub
> 'How to detect if a file already exists.
> '-------------------------------------------------------------------
> ' To detect an existing file, use the function below:
>
> 'Function FileExists%(fname$)
> 'On Local Error Resume Next
>
> 'Dim ff%
> ' ff% = FreeFile
> ' Open fname$ For Input As ff%
>
> ' If Err Then
> ' FileExists% = False
> ' Else
> ' FileExists% = True
> ' End If
>
> ' Close ff%
>
> 'End Function
>
> wrote in message
> news:[email protected]...
> > Hello AutoCAD VBA Users,
> >
> > How do I test if a file exists? I have a For Loop that will open a DXF
> > file (e.g. concatenate the loop number to the filename to come up with
> > file1.dxf, file2.dxf, etc.), do some VBA changes, then save as DWG.
> > Problem is I get an error message when a file doesn't exist.
> >
> > Thanks,
> >
> > Jeff Jensen, [email protected]
> >
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
>