LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I display the date and time of the a file in a textbox?

Hello All,

I am using Labwindows/CVI 5.01. My question is in the subject actually.
1. How can display the date and time of the file in a textbox?
2. Say if the file is in a network computer how can also display a certain file on that computer in my computer.

Hope you can help me on this thanks.

Regards,
________________________________________________________________
Electronics Manufacturing Tester Forum
0 Kudos
Message 1 of 11
(4,812 Views)
Not sure about CVI 5, but CVI 7 has library functions GetFileTime() and GetFileDate() which should be a good starting point. (There are similar versions, with the same names, in the Windows SDK in the FDS version.) Once you have the raw integer values it is easy to sprintf() them into a suitable string to display in your text box.
 
If you use FileSelectPopup(), you can use conventional Explorer methods to navigate to network or mapped drives and retrieve the same file information.
 
JR
0 Kudos
Message 2 of 11
(4,804 Views)
thanks for the reply jr,

the result of getfiledate is an integer.

Furthermore, can you give a sample.

thank you in advance.
________________________________________________________________
Electronics Manufacturing Tester Forum
0 Kudos
Message 3 of 11
(4,787 Views)

Hello, smoken

as of CVI5.5 (I cannot go back more than this) GetFileDate and GetFileTime functions give result in handy manner. As JR told you, you can use FileSelectPopup to navigate and choose the file you want, retrieve its name in a string and pass it to these functions to obtain file date and time:

char  file[MAX_PATHNAME_LEN];

FileSelectPopup ("", "*.*", "", "", VAL_SELECT_BUTTON, 0, 0, 1, 0, file);

GetFileDate (file, &year, &month, &day);

GetFileTime (file, &hour, &minute, &second);

 
As you can see in function help, the return value from the GetFilexxx functions is an error code (which I suggest you to test to give robustness to your code).
 
If you are not so fond on SDK usage, I discourage you from running that way (GetFileAttributesEx) since you will find yourself int the plague of interacting with different file date/time (creation, acce, modification) in a not-easy-to-get manner.
 
Hope this can help you
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?
0 Kudos
Message 4 of 11
(4,780 Views)
thank you all for the reply, but i dont get the point.
 
i attached the uir i made, basically when you press start it will find the file i specified coded in the source not finding yourself and will display the date of the file and time in the textbox.
 
Thank you very much!!!
 
I really appreciate it.
________________________________________________________________
Electronics Manufacturing Tester Forum
0 Kudos
Message 5 of 11
(4,758 Views)
Where exactly is your problem? Creating the string with date and time? Writing it down to the textbox? Managing errors? If you are more precise we can help you a little more...


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?
0 Kudos
Message 6 of 11
(4,737 Views)

Hello Roberto,

Thank you for answering my query, here's the details, I want to put the date of the file when it was created. Say the creation date and time of the file is 1/26/2006 7:00:00 AM, then the textbox in the uir will display  "The file was created:  1/26/2006 7:00:00 AM".

Again, thank you!!!

 

Regards,

Leo

________________________________________________________________
Electronics Manufacturing Tester Forum
0 Kudos
Message 7 of 11
(4,718 Views)

Leo, copying these lines in the Interactive execution window and adjusting the filename you'll get the file time and date displayed in a popup message. Just substitute the last MessagePopup with a ResetTextBox on the textbox gives you a solution. You may want to customize the output message to your desires. Here's the simple parte of the answer.

The problem is that these lines give you the date / time of last modification on the file, NOT the creation date and time! If you reallt need these you'll have to deal with SDK functions.

#include <userint.h>
#include <ansi_c.h>
#include <utility.h>
static int  mm, dd, yy;
static int  hh, mn, ss;
static int  err = 0;
static char msg[512], file[MAX_PATHNAME_LEN];

strcpy (file, "C:\\MyFile.txt");
if (err = GetFileDate (file, &mm, &dd, &yy)) {
 MessagePopup ("Error", "Error in GetFileDate.");
 goto Error;
}
if (err = GetFileTime (file, &hh, &mn, &ss)) {
 MessagePopup ("Error", "Error in GetFileTime.");
 goto Error;
}
sprintf (msg, "File: %s\n\nDate: %d/%d/%d\nTime: %02d:%02d:%02d", file, mm, dd, yy, hh, mn, ss);
MessagePopup ("Details", msg);
Error:
;



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 8 of 11
(4,695 Views)

Thank you jr and roberto,

I finally figured it out!!!Thank you very much for helping me!!!

Regards,

________________________________________________________________
Electronics Manufacturing Tester Forum
0 Kudos
Message 9 of 11
(4,672 Views)

Hello Roberto, 

 

                       I have labwindows cvi application running. I want a message box pop up and say "Sorry your time has expired to use this application" on particular date. (Calculated using getsystemdate)

 

                        And then when they hit ok to that message box close the CVI app. Can you please help me with the same. 

0 Kudos
Message 10 of 11
(2,883 Views)