How to know if a file exists and how to create it?

How can I know if a file exists and If it doesn´t, how could I create an empty txt file?

Regards
dimensionavAsked:
Who is Participating?
 
Martin LissOlder than dirtCommented:
To put it all together

If Dir("C:\Test.txt") <> "" Then
  Msgbox "File exists"
Else
  Open "C:\Test.txt" For Output As #1
  Close
End If
0
 
Martin LissOlder than dirtCommented:
If Dir("C:\Test.txt") <> "" Then
  Msgbox "File exists"
Else
  Msgbox "File does not exist"
End If 

Open in new window

0
 
Rob MinersCommented:
@echo off
c:
if not exist C:\test.txt echo. > c:\test.txt
0
 
Martin LissOlder than dirtCommented:
To create a blank file just issue an Open statement for the file you want.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.