LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

input value + search file

Hello,
I have some Problems now.
I will input a (File.txt) Name in my string window on my panel.
Then I will search this file on my Harddisk d:
I wrote this c-text, but my program did not found my file!

static char buffer[30];
static int result;
static IniText g_myInifile;

main...

int CVICALLBACK Suchen (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:

GetCtrlVal (panelHandle, PANEL1_GEWNR, buffer);

result = FileExists("d:\\buffer.dat",0); //Exist File

if (result==0)
MessagePopup ("Werte", "Artikelnummer unbekannt. Es wurde keine Tastatur gefunden!!!");

if (result==1)
{
MessagePopup ("Werte", "Datei für
diese Tastatur wurde gefunden!!!");
}

break;
}

return 0;
}

Can s.b can my explain my mistake?
Thank you!
0 Kudos
Message 1 of 3
(3,017 Views)
In your routine you retrieve the file name input by the operator into the variable , next you look for the file:

result = FileExists("d:\\buffer.dat",0); //Exist File

With this statement, you are actually looking if a file named "buffer.dat" exists on D disk, not the file indicated by the operator!

If the operator inputs a full file name (with extension), you can pass it directly to FileExists function:

result = FileExists (buffer, 0); //Exist File

On the other side, if you are sure the operator inputs a file name without extension and you want to look for the file named .dat, you must appropriately format the filename to pass to the FileExists function, this way:

char file[MAX_PATHNAME_LEN];
sprintf (file, "d:\\%s.d
at", buffer);
result = FileExists (file, 0); //Exist File

But since you assume the operator has to input some value, maybe you can use the FileSelectPopup function which is powerful and restitutes a full pathname you can pass directly to FileExists function instead of simply asking for a filename.

Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(3,017 Views)
Thank you Roberto for this good answer of my problem.
Greetings Thomas
0 Kudos
Message 3 of 3
(3,017 Views)