Page 1 of 1

check if a file exists in the server

Posted: October 10th, 2022, 10:25 am
by AriSilva
Hi folks,
I have an applicaton that stores auxiliar data in the server, not the interviews.
Later, I need to check if the data is there, that is, if there is a file wich such and such name, but I do no want to GET the file, as in the syncdata function.
I just want to see if the file exists. I might ise the syncdata, but there are many files and sometimes they are big, I wold not like to spend time downloading them just to see if they exist. I know that the syncdata returns a false when the file does not exist, and this is good, but if the file exists, I am waisting time finishing thesyncdata operation.
I thought about having an universe in the syncdata, but what kind of expression should I use in this case?
Can I limit the syncdata by saying "just x cases"?
Best
Ari

Re: check if a file exists in the server

Posted: October 11th, 2022, 10:44 am
by sherrell
Hi Ari,

I haven't done this with a server, but does the https://www.csprousers.org/help/CSPro/f ... ction.html not work for you?

Of similarly, the https://www.csprousers.org/help/CSPro/f ... ction.html function? (which returns default if the file doesn't exist).

Hope all is well with you.

Sherrell

Re: check if a file exists in the server

Posted: October 11th, 2022, 3:16 pm
by AriSilva
Hi Greg,
As a matter of fact, I did not try either one, since they (presumably) uses a filename as a parameter.
The syncfile also uses filenames as parameters, such as in
if syncfile(GT, sourceFile, targetFile) then....)
but it assumes that the sourceFile, is in the server. which I previously syncconnect.
Suppose I write something like
string sourcefile = "PDP\file_in_Server.dat";
string targetfile = ".\target.dat";
string serverx = "www....../api";
and then
if syncconnect(csweb, serverx) then
if fileexist(sourcefile) //this should not work
Is it possible to concatenate the server name and the source file name, such as in
string serverfile = concat(serverx, "/", sourcefile);
and then
if fileexist(serverfile) then ...
Best
Ari

PS. All is pretty well down here, considering, and what about you?

Re: check if a file exists in the server

Posted: October 14th, 2022, 12:59 pm
by sherrell
>Hi Greg,

You've got Sherrell writing to you! :)

And Greg is out this week, because he otherwise would have corrected me, as the functions I referenced can only be used on the local (Android/PC) device. So to check on server files, probably the only function that could be used would be SyncTime:

https://www.csprousers.org/help/CSPro/s ... ction.html

See Example 2 on that page. You could use the "never synched" to mean the file doesn't exist.

>PS. All is pretty well down here, considering, and what about you?

LOL on "considering". Yup, everything considered, it's going as well as can be.

Have a good weekend!
Sherrell

Re: check if a file exists in the server

Posted: October 16th, 2022, 10:19 am
by AriSilva
Thanks, Sherrell,
Sorry, but no cigar with the synctyme.
The syntime function refers (as much as I could see) to files having dictionaries, and stored in the server as well.
The files I wanted to know about are not stored under a dictionary, or being accessed through a dictionary: they are files stored in the server under another directory, and accessed by syncfile, nor syncdata
Best
Ari

Re: check if a file exists in the server

Posted: October 16th, 2022, 12:28 pm
by sherrell
Hi Ari,

Where exactly are they in the folder structure? Within the CSEntry application you're deploying, or something totally different? For due to the more restrictive conditions placed by Android 11, even if we were to develop something, it likely wouldn't work outside your application's folder. I'll let Greg answer this tomorrow to confirm/deny, but you may be up against that.

Sherrell

Re: check if a file exists in the server

Posted: October 17th, 2022, 9:53 am
by AriSilva
Hi Sherrell,
The files are already in the csw server.
They were uploaded by the syncfile function (PUT), stored in a common folder in the server.
What I need is, in windows, using a cspro application, see if the file(s) (one for each census tract), are stored in the server.
The files are NOT the interviews themselves, but support files having addresses and stuff like that, so, they are a part from the interviews.
I can download them using syncfile(GET), and if the function returns false that means the file is not there in the server, but this solution is very time consuming for my purposes of just to see if the files exist.
Got it?
Best
Ari

Re: check if a file exists in the server

Posted: October 18th, 2022, 11:01 am
by sherrell
Hi Ari,

Ignore my comments on Android 11 with regard to the server! What I was trying to ascertain is where on the server your file is; i.e., is it within the CSWeb installation area (I will assume yes) or is it outside that (which CSEntry invoking CSWeb wouldn't have access to). Greg mentioned that if you were running several surveys on a single installation of CSWeb, they would all be able to access one another. If you didn't want that to happen, you'd have to setup up multiple CSWebs.

But as to your request, this is something that others have asked for, and is hopefully something we could do in an upcoming release. It would require an update to the CSWeb software as well in order for it to support this. I know this doesn't help you now, but it is on the guys' radar.

Thanks,
Sherrell

Re: check if a file exists in the server

Posted: October 19th, 2022, 8:27 am
by AriSilva
Thanks, Sherrell, for your reply.
I´m working with different csweb servers, one for each survey, for several reasons, one of them is that I want to preserve some security, not allowing the interviewers for a survey to have access to another survey´s questionnaires.
In any case, please, as soon as (and if) you program that new function, just tell me.
Meanwhile I´m using the syncfile(get) to download the files in the server, and if the function returns false I´ll know the file does not exist there, even if it takes a little longer, but I can survive that.
Best
Ari