The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Is there any way to preserve lead zeros?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

liangz

Canada
4 Posts

Posted - 06/26/2001 :  2:29:54 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I am writing a program to automatically process some files and manipulate them. At this stage, I am trying to allow the program to automatically find files with a certain format and import them. To do this, it needs to recognize lead zeros (i.e. 000.xls). Is there any way to allow these lead zeros to be preserved if I make a loop to continually import a series of files of this nature (n=000; n++)?

Mike Buess

USA
3037 Posts

Posted - 06/27/2001 :  3:37:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If I understand you correctly, you want to import files with the XLS extension and 3-digit file names (001.xls, 002.xls, ...). You can try something like this, which generates all possible 3-digit file names (extending this to more digits should be trivial) and for each case finds out if a file with that name exists.
%B=[folder name & path];
loop (ii,1000,1999) {
%A=$(ii); %A=%[%A,>2];
[if the file %B%A.xls exists, import & manipulate it];
};
How you find out if the file exists depends on which version of Origin you have. In Origin 6.1 you can use the exist() function:
exist(%B%A.xls)=file size in KB or -1 if the file doesn't exist
You might also find the OFileMan add-on useful in Origin 6.1. Finally, the Origin Professional (5.0 or later) file.exists() command returns 1 if its argument exists and 0 or -1 (not sure which) otherwise.

I hope that helps. Please set me straight if I misunderstood your question.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 06/27/2001 15:39:43

Edited by - Mike Buess on 06/27/2001 15:41:07
Go to Top of Page

rtoomey

USA
184 Posts

Posted - 06/27/2001 :  3:44:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This might be a similar idea to Mike's, but here goes:

You would need to create and utilize a string variable (e.g. %A) which pads n with leading zeros by checking its character length.



The script below is an example. It uses ii instead of n.





for(ii=1;ii<=10;ii++)
{
%A=$(ii);
if(%[%A]==1)
{
%A="00$(ii)";
}
if(%[%A]==2)
{
%A="0$(ii)";
}
%A="%Afile.xls";
type -a "The filename is: %A";
}




To execute the script and view its output:


  1. Copy and paste the script into the Origin Script window (Window => Script Window).
  2. Highlight the script.
  3. Press the ENTER key on your keyboard.



Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 06/28/2001 :  09:23:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
An alternative to creating the file names and then checking for their existance is to create a list of all files in a folder and check each filename to see if it matches your pattern. (That approach will probably be a bit faster.) You can get the file list in Origin 6.1 with the OFileMan add-on that I mentioned in my earlier post and in Origin 5.0 or later you can use my FileList scripts. I would loop through the filenames, assign each to the variable %A and use a two-part pattern test:
// Test 1 - Skip the file if its extension isn't xls
if("%[%A,>%[%A]-2]"!="xls") continue;
// Test 2 - Skip the file if every character in its name isn't a number
stat=0;
loop (j,1,%[%A]-3) {
if(%[%A,j:j]==0/0) {stat=1; break};
};
if(stat==1) continue;

// if it passes both tests, then import & manipulate

With my FileList scripts you can list only the files with the XLS extension, which would avoid the first test. There might also be a better way to perform the second test.

Mike Buess
Origin WebRing Member

PS: The new version of the FileList scripts can be run without user modifications to the accompanying batch file.

Edited by - Mike Buess on 06/28/2001 11:31:07
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000