LabWindows/CVI Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
Floridaking

FileSelectPopup

Status: New

Add an option in FileSelectPopup() to escape the backslash (\) to (\\) in path names.  CVI and Win-7 do not work with single backslashes in path names.

 

example: 

  fp=fopen("C:\temp\TEST.txt","w"); // open the file for writing  *** Will not work. ***

 

  fp=fopen("C:\\temp\\TEST.txt","w"); // open the file for writing  *** Good ***

 

If we can add the backslash(s) in using a FileSelectPopup() option, this problem goes away.  

9 Comments
RobertoBozzolo
Proven Zealot

The problem with backslashes is not related to CVI and Win7, every C compiler interprets a backslash as a special key code together with the character that follows it.

I don't understand your comment about FileSelectPopup: the pathname returned by that function can be directly passed to fopen or whichever function you want without need for further processing.

On the other hand, if you need to build a pathname from scratch, I suggest you look at MakePathname function that correctly builds up the pathname in a string variable.



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?
Floridaking
Member

I am using CVIFUNC FileSelectPopup found in:

   http://zone.ni.com/reference/en-XX/help/370051M-01/cvi/uiref/cviuser_interface_library_function_/

 

This function FileSelectPopup()  does Not correct the backslash issue.

 

I lookeded for MakePathname and did not see it in the list of CVI functions above.

 

Norm

RobertoBozzolo
Proven Zealot

Let me rephrase my post another way. If you write strcpy (string, "C:\temp") the compiler treats the backslah "\" as a special chacter, an escape code that together with the following character has a special meaning. In your case, "\t" is equivalent of embedding a tabulator in the string. If you happen to look at 'string' in the variables window you will see it as "c: emp", where the empty space is not a real space (code 32) but a TAB (code 9).

Other escape codes can be "\n" (new line), "\r" (linefeed) and so on. To embed a simple backslash in the string you must use a special escape code which is "\\". If you write strcpy (string, "C:\\temp") you will see the correct value in string: "c:\temp".

 

Now, strings returned from FileSelectPopup are in this form, with actual backslashes embedded, and as I already told you can be directly passed to fopen without problems.

 

MakePathname is part of the Utility library. Simply include the function in your code and the IDE will add the corresponding include file in it.



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?
Floridaking
Member

Thank you, we agree that the backslash requires special handling.  My point is that I expected a function that is designed to import a path name that is likely to contain backslashes, should account for this well-known issue so that a folder separator "\" is not mixed up with an escape charter.  I am suggesting that This function, FileSelectPopup(), be improved to better handle the backslash.  Why offer a function that passes back a pathname charter string that does not work?     

  

Norm

Floridaking
Member

I believe your statement is Not correct:   ". . . about FileSelectPopup: the pathname returned by that function can be directly passed to fopen or whichever function you want without need for further processing." 

 

I did pass the pathname returned by the function  FileSelectPopup()  to fopen() and it did not work.  I then added extra backslashes and it did work, see my first statement.

 

Norm

Wolfgang
Trusted Enthusiast

Hi Floridaking,

 

In general I would think that it is a good idea to discuss such issues in the CVI discussion forum first. If a function behaves different than expected it may be either a bug of CVI - or a mistake/misunderstanding of the user

 

I suggest to have a look at the example program popups shipping with CVI which nicely demonstrates that you indeed can directly use the pathname. The relevant code is:

 

        if (FileSelectPopupEx ("", "*.dat", "datafile", "This is a File Select Popup", VAL_SAVE_BUTTON, 0, 0, filename) != VAL_NO_FILE_SELECTED)
            {
                pfile = fopen (filename,"w+");
                fwrite (datapoints, 8, 100, pfile);
                fclose (pfile);
            }

Floridaking
Member

Given my experience with this problem, you are partly right.  The function FileSelectPopup() will work if the user does not select a path and only enters a file name.  The new file will go in the current folder used to run the application, no backslashes are included in the filename.    If the user choses a different folder, then backslashes are required in the name and returned by FileSelectPopup().  In this case, the pathname will fail when used in the fopen().  I have tried this several times.   

 

I see that the example you refer to: FileSelectPopupEx

is not the same as the one I am talking about: FileSelectPopup

 

I also see that FileSelectPopupEx is Not found in:

   http://zone.ni.com/reference/en-XX/help/370051M-01/cvi/uiref/cviuser_interface_library_function_/

 

Norm

Floridaking
Member

Do you know the diference between the function FileSelectPopupEx and FileSelectPopup?

Wolfgang
Trusted Enthusiast

FileSelectPopupEx is the newer variant. The previous version FileSelectPopup is still valid

 

By the way, you can use FileSelectPopup to change the current directory to save the file somewhere else, e.g. on the desktop - it works, too.