10-10-2011 03:28 AM
Hi:
I want to confirm a file at a web server, so which function can I use?
Thanks
10-11-2011 01:08 AM
int GetFileInfo (char *fileName, long *fileSize); will be OK.
int GetFileInfo (char *fileName, long *fileSize);
Verifies whether a file exists. Returns an integer value of zero if no file exists and one if the file exists. fileSize is a long variable that contains the file size in bytes or zero if no file exists.
/* Check for presence of file A:\DATA\TEST1.DAT. */
/* Print its size if file exists or message that states file does not exist. */
int n;
long size;
n = GetFileInfo("a:\\data\\test1.dat",&size);
if (n == 0)
FmtOut("File does not exist.");
else
FmtOut("File size = %i[b4]",size);
Input | ||
Name | Type | Description |
fileName | string | Pathname of the file to check. |
Output | ||
Name | Type | Description |
fileSize | long | File size in bytes. fileSize is zero if no file exists. |
Name | Type | Description | ||||||||
status | integer | Indicates whether the specified file exists.
You can use GetFmtIOError to get more information about the type of error that occurred. |
06-16-2014 09:02 AM
I am using LabWindows/CVI 2010, to create a distribution of a program that was previously built in an older version of CVI. Each time I try to build the distribution, I receive an error related to the GetFileInfo function that reads as follows:
(24, 42 Type error in argument 2 to `GetFileInfo'; found 'pointer to long' expected 'pointer to ssize_t'.)
From what I can gather, it seems that the former declaration of a "long" variable called "filesize" has been replaced by a variable type of "ssize_t". Is this correct, and if so, then will it work for me to replace the variable type for the variable "filesize" at its declaration without having to change anything else? I am remiss to change much of this code without some levels of assurance since its original author is no longer around and little documentation remains for explaination of it's original development.
and the code segment in question is:
void ForceUniqueFilename(int panelHandle, int controlID)
{
int i, cnt;
long filesize;
/* Prepare filename to open data file in case "save data to disk" button is enabled */
GetCtrlVal(panelHandle,controlID,filespec);
cnt=0;
while (GetFileInfo(filespec,&filesize)){
/* current file name exists, add a number in sequence to make it unique */
SplitPath(filespec,driveName,dirName,fileName);
i=StringLength(fileName)-4; /* name minus forced extention of ".RAW" */
fileName[i--]=0; /* replace period with ASCII null to terminate string */
while (isdigit(fileName[i]) && i!=0){
i--; /* move left one char in file name */
}
if (i==0 && isdigit(fileName[0])){
/* bizarre but possible case where base filename is simply a number */
Scan(fileName,"%s>%i",&cnt);
cnt++; /* create next name in numerical sequence */
Fmt(fileName,"%s<%i%s",cnt,".BIN");
}
else{
if (fileName[i+1]!=0)
Scan(&fileName[i+1],"%s>%i",&cnt);
cnt++;
Fmt(&fileName[i+1],"%s<%i%s",cnt,".BIN");
}
Fmt(filespec,"%s<%s%s%s",driveName,dirName,fileName);
}
SetCtrlVal(panelHandle,controlID,filespec);
}
06-16-2014 09:46 AM
Yes, you are correct, the parameter fileSize has changed from long (up to including CVI9) to ssize_t from CVI2009 onwards since CVI2009 introduced the possibility of building 64bit applications. sszie_t will translate to either 32 bit or 64 bit integers depending of the application you are building (32 bit vs. 64 bit).
So changing your fileSize parameter to ssize_t should solve your problem
06-16-2014 11:22 AM
thank you.