Comapering file names

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have written a program that creates a report, names and saves it in a
specific folder. I would like to make sure that if the user tries to save the
report again it does not overwrite the first one. Basically I need to be able
to loop through all the files in the folder to see if the report exists and
if it does quit or change the name before saving the new one. What I am
failing to do is come up with the right filesystemobject code to use. HELP!!



Thankyou in advance
 
To determine if a file exists, check:
If Len(Dir(strFileName)) > 0 Then ' file exists
 
I still think I am having a problem. The LEN(dir(filename)) returns the
number of charecters, since I have a lot of files in the same folder with
similar number of charecters but different names I need a way to actually
compare the existing file name to the new one so as not to replace that
specific file. For instance if you try to save an existing file in a disk you
get a message asking you if you want to replace that file. This is the
function I would like to add to my program.

I appologise for my obvious stupidity but any help will be appreciated.
 
If strFileName contains the full path to the file, then Dir(strFileName)
will return the file name (without the path information) if the file exists,
or a zero-length string ("") if it doesn't. Therefore,
Len(Dir(strFileName)) will be non-zero if the file exists, or 0 if it
doesn't.
 
Back
Top