PDA

Click to See Complete Forum and Search --> : simulating VB's Dir function


amcrae
Aug 23rd, 2000, 10:00 PM
can I easily check for the existance of a certain file?

with VB would just use Dir(FileName), an empty string returned would indicate that the file doesnt exist. Can I do something similar with C++?

Aug 24th, 2000, 06:05 PM
use the undocumented SHFileExists function.

here is the declaration in vb, if you can convert it to C++ good luck!


Private Declare Function SHFileExists Lib "shell32" Alias "#45" (ByVal szPath As String) As Long

Cybrg641
Aug 24th, 2000, 09:36 PM
Put this in to the OnClick Event of some control


AnsiString asFileName = FileSearch(Edit1->Text, GetCurrentDir());
if (asFileName == "")
Application->MessageBox(("Couldn't find " + Edit1->Text + ".").c_str(), "FileSearch Example", IDOK);
else
Application->MessageBox(("Found " + asFileName + ".").c_str(), "FileSearch Example", IDOK);


I hope this works!:)