Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileExists not working...

Status
Not open for further replies.

dhamal1

IS-IT--Management
Jan 7, 2008
6
US
Hi,
I need to check if .doc file exist in a folder called My Documents but it seems to be not working. dont know what am i going wrong:
Set filesys = CreateObject("Scripting.FileSystemObject")
Set NewFolder = filesys.GetFolder("C:\My Documents")
If filesys.FileExists(NewFolder & "\") Then

msg = " exists."

Else

msg = " doesn't exist."
 
1) "NewFolder" is a Folder Object Reference
2) "\" isn't a file name.

The FileExists method of the File System Object expects it's input to be a string containing the file name with or without the full path.

Use:

If filesys.FileExists([red]"C:\My Documents\Myfile.doc"[/red]) Then


PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
...or use FolderExists if you're testing for the existance of a folder.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
i got the solution. I can not use fileexists becaseu i am checking if there is file in the folder or not as i dont know the file name. Solution is: for loop to count file in the folder.
 
or newfolder.files.count

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top