Dear all,
We use a report system based on Cspro form. More than 20 persons are using laptops and a server on a LAN. Whole files (Application, Data) are located on the server. Data File is a combination of data entry clerk name and laptop username.
For example, the name of data entry clerk are: DEC(i) where i is the persons number. And the username of laptops are: laptop(i) where i is the laptop number so, finally data file name are DEC1_LAPTOP1 (the first data entry clerk using the first laptop)
But, for several reasons, sometimes data entry clerk change laptops. It's because i would like to write a code to Seek previous datafile of this clerk and rename it according of the name of actual laptop,so clerks could continue to work on previous data.
This must be easy... For example, if the data file name is DEC1_LAPTOP1 and now DEC1 use LAPTOP2, the code must be something like this via the menu.
If fileexist(DEC1_LAPTOP1.dat") and (getusername()=LAPTOP2 and getoperatorid()=DEC1)
then filerename(DEC1_LAPTOP1.dat, "c:\folder\DEC1_LAPTOP2.dat");
endif;
Please, more help to finalize this code!
Thanks in advance!
Dynamic change of data file name (Fileexist/Filerename)
Dynamic change of data file name (Fileexist/Filerename)
G.VOLNY, a CSProuser from Haiti, since 2004
Re: Dynamic change of data file name (Fileexist/Filerename)
The code looks reasonable to me. Is it not working?
Re: Dynamic change of data file name (Fileexist/Filerename)
Dear Josh,
The problem is to do it dynamically...I try to think this code:
string dataname=concat(strip(clerk_name),"_",strip(clerk_surname));//clerk_name and clerk_surname are two item in the menu.
string usern=getusername();
string datafilename=dataname+"_"+usern+"."+dat;
//I imagine that i must write a function is to seek if the portion of name of a specific data entry clerk exist in the data file name by using the pos function...But, it's not clear for me if a user defined function is useful to do it.
If fileexist (pos ("dataname","data file name")>0 ) //Assuming that clerk_name is Jean and clerk_surname is valjean and the username is laptop1 so, the datafilename will be jean_valjean_laptop1
But, i want only to know if in the data folder, jean valjean already enter data from whatever laptop. So,my idea is to use pos to analyze if this
portion:jean_valjean exist in the data file name...pos (dataname)>0, because the logic find the portion of dataname in the data file name.
then filerename(dataname_xxxx.dat, "..\data\datafilename");// Must rename the existing data file containing jean_valjean regardless of usern(xxxx)
endif;
Please, let me know if my idea is clear for you.
Thank you!
The problem is to do it dynamically...I try to think this code:
string dataname=concat(strip(clerk_name),"_",strip(clerk_surname));//clerk_name and clerk_surname are two item in the menu.
string usern=getusername();
string datafilename=dataname+"_"+usern+"."+dat;
//I imagine that i must write a function is to seek if the portion of name of a specific data entry clerk exist in the data file name by using the pos function...But, it's not clear for me if a user defined function is useful to do it.
If fileexist (pos ("dataname","data file name")>0 ) //Assuming that clerk_name is Jean and clerk_surname is valjean and the username is laptop1 so, the datafilename will be jean_valjean_laptop1
But, i want only to know if in the data folder, jean valjean already enter data from whatever laptop. So,my idea is to use pos to analyze if this
portion:jean_valjean exist in the data file name...pos (dataname)>0, because the logic find the portion of dataname in the data file name.
then filerename(dataname_xxxx.dat, "..\data\datafilename");// Must rename the existing data file containing jean_valjean regardless of usern(xxxx)
endif;
Please, let me know if my idea is clear for you.
Thank you!
G.VOLNY, a CSProuser from Haiti, since 2004
Re: Dynamic change of data file name (Fileexist/Filerename)
Could you use the dirlist function to do this? Dirlist will give you the names of all the files in the directory and then you could compare each one to the clerks data file name using pos. Something like this:
string dataname=concat(strip(clerk_name),"_",strip(clerk_surname));//clerk_name and clerk_surname are two item in the menu.
list string fileListing;
numeric i;
dirlist(fileListing,"C:\data","*.dat");
do i = 1 while i <= length(fileListing)
string fname = fileListing(i);
if pos(dataname, fname) > 0 then
filerename(fname, "C:\data\" + dataname + getusername() + ".dat");
endif;
enddo;
list string fileListing;
numeric i;
dirlist(fileListing,"C:\data","*.dat");
do i = 1 while i <= length(fileListing)
string fname = fileListing(i);
if pos(dataname, fname) > 0 then
filerename(fname, "C:\data\" + dataname + getusername() + ".dat");
endif;
enddo;
Re: Dynamic change of data file name (Fileexist/Filerename)
Thank you Josh! That's work very well this new function.
Thanks a lot for your precious help since months!
Thanks a lot for your precious help since months!
G.VOLNY, a CSProuser from Haiti, since 2004
Re: Dynamic change of data file name (Fileexist/Filerename)
Dear all
I tried to duplicate what you are proposing to rename all files generated during the running of data entry application including data file but I can't.
I think this should help to have automatically different names of data file on different tablets by using the same pff and pen files.
I created for instance in the data dictionary four variables called tablet_Num, clerk_name, clerk_surname and datafile.
As you can observe below, in the Proc Datafile, I would like to rename all files generated during the running of CSentry application including the data file declared "Data" in pff file by "Clerk_name+clerk_surname+Tablet_Num.dat".
As result, only one file named "Data.log" is renamed (as for instance Data001.dat) and by continuing entering data, another "Data.log" file is created while Data001.dat doesn.t change i.e is not updated.
Please, could you help and elaborate more on filerename function?
Thanks
PROC DATAFILE
Preproc
If demode() = Add then;
i = 0;
String dataname = concat(strip(clerk_name), strip(clerk_surname));
Dirlist(fileListing,"E:\GANA\FINSCOPE\2015\CAPI","Data.*");
Do i = 1 while i <= length(fileListing)
String Ofname = fileListing(i);
If pos(dataname, Ofname) > 0 then;
filerename(Ofname, "E:\GANA\FINSCOPE\2015\CAPI\" + dataname + Tablet_Num + ".dat");
Endif;
Enddo;
Endif;
I tried to duplicate what you are proposing to rename all files generated during the running of data entry application including data file but I can't.
I think this should help to have automatically different names of data file on different tablets by using the same pff and pen files.
I created for instance in the data dictionary four variables called tablet_Num, clerk_name, clerk_surname and datafile.
As you can observe below, in the Proc Datafile, I would like to rename all files generated during the running of CSentry application including the data file declared "Data" in pff file by "Clerk_name+clerk_surname+Tablet_Num.dat".
As result, only one file named "Data.log" is renamed (as for instance Data001.dat) and by continuing entering data, another "Data.log" file is created while Data001.dat doesn.t change i.e is not updated.
Please, could you help and elaborate more on filerename function?
Thanks
PROC DATAFILE
Preproc
If demode() = Add then;
i = 0;
String dataname = concat(strip(clerk_name), strip(clerk_surname));
Dirlist(fileListing,"E:\GANA\FINSCOPE\2015\CAPI","Data.*");
Do i = 1 while i <= length(fileListing)
String Ofname = fileListing(i);
If pos(dataname, Ofname) > 0 then;
filerename(Ofname, "E:\GANA\FINSCOPE\2015\CAPI\" + dataname + Tablet_Num + ".dat");
Endif;
Enddo;
Endif;
Re: Dynamic change of data file name (Fileexist/Filerename)
Dear Ganas,
I use the same code but through a menu. Since CSPRO files are read-only, we can't rename them while the're are in use. Do you use a menu with your application?
Regards,
I use the same code but through a menu. Since CSPRO files are read-only, we can't rename them while the're are in use. Do you use a menu with your application?
Regards,
G.VOLNY, a CSProuser from Haiti, since 2004
Re: Dynamic change of data file name (Fileexist/Filerename)
Dear htuser,
Thanks.
Sorry, I don't how to use menu. Could you give me some guidance or reference?
Regards
Thanks.
Sorry, I don't how to use menu. Could you give me some guidance or reference?
Regards
Re: Dynamic change of data file name (Fileexist/Filerename)
Dear Ganas,
Please go to http://teleyah.com/cspro/DCJune2015/10-Menu/10-Menu.pdf and http://teleyah.com/cspro/Lesotho/09-Menu-Programs.pdf (Thanks to Josh)
You'll have detailled explanation and codes examples.
Regards,
Please go to http://teleyah.com/cspro/DCJune2015/10-Menu/10-Menu.pdf and http://teleyah.com/cspro/Lesotho/09-Menu-Programs.pdf (Thanks to Josh)
You'll have detailled explanation and codes examples.
Regards,
G.VOLNY, a CSProuser from Haiti, since 2004
Re: Dynamic change of data file name (Fileexist/Filerename)
Dear htuser,
Received with many thanks. Let me try and I will let you know the progress.
Regards.
Received with many thanks. Let me try and I will let you know the progress.
Regards.