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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Is there any way to preserve lead zeros?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
liangz Posted - 06/26/2001 : 2:29:54 PM
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++)?
3   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 06/28/2001 : 09:23:32 AM
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
rtoomey Posted - 06/27/2001 : 3:44:07 PM
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.



Mike Buess Posted - 06/27/2001 : 3:37:36 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000