Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

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
0
dimensionav
Asked:
dimensionav
  • 3
1 Solution
 
Martin LissRetired ProgrammerCommented:
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 LissRetired ProgrammerCommented:
To create a blank file just issue an Open statement for the file you want.
0
 
Martin LissRetired ProgrammerCommented:
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now