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
 Origin Forum
 labtalk syntax to copy filename

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
EigenGoofy Posted - 05/12/2011 : 4:30:33 PM
By importing Multiple ASCII or importing Wizard, the data from two files "r1T.XVG" and r2E.XVG" have been added on the two columns A and B on a worksheet. Then I need write comments on the column A by typing "r1T", and on the column B by typing "r2E".

Question:
How can I use labtalk syntax or script to copy the filename "r1T.XVG" without ".XVG" to the comment table on the column A without directy typing?
5   L A T E S T    R E P L I E S    (Newest First)
EigenGoofy Posted - 05/13/2011 : 9:31:20 PM
quote:
Originally posted by easwar

Hi,

Here is another possible solution:
1> Use import wizard to import your multiple files

2> On first page of wizard set Import Mode drop-down to "Start New Columns" so all files come into same sheet as new columns

3> On the 2nd page (File name Options), under Append, check the "file name to column comments" check box, and uncheck the "Include path when appending file name"

4>Then in the Advanced Options page, put this script:
for(int ii=1; ii<=wks.ncols; ii++)
{
string str$=wcol(ii)[C]$;
wcol(ii)[C]$ = str.GetToken(1,'.')$;
}


Then the script will remove the file extension part from the comments from all columns.

Easwar
OriginLab




Oh, my god. I always had a super-long name on the tables of comments until now I just know from Easwar that there is a GOLDEN box hiden there so that I can uncheck the "Include path when appending file name"!

Thank you, Easwar and your "for" sentence...

easwar Posted - 05/13/2011 : 7:15:02 PM
Hi,

Here is another possible solution:
1> Use import wizard to import your multiple files

2> On first page of wizard set Import Mode drop-down to "Start New Columns" so all files come into same sheet as new columns

3> On the 2nd page (File name Options), under Append, check the "file name to column comments" check box, and uncheck the "Include path when appending file name"

4>Then in the Advanced Options page, put this script:
for(int ii=1; ii<=wks.ncols; ii++)
{
string str$=wcol(ii)[C]$;
wcol(ii)[C]$ = str.GetToken(1,'.')$;
}


Then the script will remove the file extension part from the comments from all columns.

Easwar
OriginLab
EigenGoofy Posted - 05/13/2011 : 6:10:45 PM
quote:
Originally posted by greg


// Get the file + ext
string strFile$ = page.info.system.import.filename$;
// Get the ext
string strExt$ = strFile.GetFileExt()$;
// Get the file - ext
strFile$ = strFile.Left(strFile.Len() - strExt.Len() - 1)$;
wcol(wks.ncols)[C]$ = str$;




Thank you, greg!
However, if using the code on the first line:

string strFile$ = page.info.system.import.filename$;

This will only assign one of the filename to strFile$, say, strFile$ = r2E.XVG. And r1T.XVG must be totally missing. After you mentioned, I have just checked the Organizer, and confirmed that although I imported from two different files, but the resulting filename shall only be one of the two filenames. On the Organizer, if look at Imported Files, there are TWO different Filenames which are wanted to apply to comments on the column A and column B. So I have tried, like:

string strFile$ = Imported Files.name$;

However, it can not work.

One of the staff here told me to use the following code to get rid of extension:

bbb$ = strFile.GetToken(1,".")$;

Which works!

Thank you again, greg. I am looking forward to see how you get the two different imported filenames, such as r1T and r2E, by using perhaps two different strings.
greg Posted - 05/13/2011 : 4:57:22 PM
The data you are trying to get is in a tree stored in the page.
You can see the info by showing the Organizer. (Right click on the Workbook Title bar.) And although OriginC has a direct method to get a filename without the extension, you can do it in LabTalk with a few extra steps.

Here is an example that reads the filename (minus the extension) and applies it to comments:

// Get the file + ext
string strFile$ = page.info.system.import.filename$;
// Get the ext
string strExt$ = strFile.GetFileExt()$;
// Get the file - ext
strFile$ = strFile.Left(strFile.Len() - strExt.Len() - 1)$;
wcol(wks.ncols)[C]$ = str$;

and here is a variation that writes to a custom header row:

string strFile$ = page.info.system.import.filename$;
string strExt$ = strFile.GetFileExt()$;
strFile$ = strFile.Left(strFile.Len() - strExt.Len() - 1)$;
wks.userparam1$ = FileName; // Define a user parameter row
wks.userparam1 = 1; // Show it
wcol(wks.ncols)[FileName]$ = strFile$;

BTW : The File Name Options page of the Import Wizard has a check box to Append file name to column comments. You need a script only because you do not want the extension.
EigenGoofy Posted - 05/12/2011 : 10:28:49 PM
Let's explan more specific.

When using "Import Wizard", click "next" multiple times until reaching to the last page where it asks to save the Filter, then tick the box which indicates "Specify advanced filter options" and click "next" again. It follows that a window asks to write labtalk code which will be executed after a successful import.

Here, I expect to write segment of labtalk code which will copy the filenames without extension suffix to the comment table on the column A and column B respectively. And this code shall be a little more applicable than just one case. For example, if the two files are not "r1t.XVG" and "r2E.XVG", but "wTj.XVG" and "wFe.XVG", then the exactly same code will copy "wTj" to the comment on the column A, and "wFe" to the comment on the column B, rather than still to copy "r1t" to column A and "r2E" to column B; in other words, without specifying the corresponding filepath, the code is able to recognize the filename.

Actually, I find that the Main header (MH) of a file contains the information of filename. I have tried to copy the information from MH to comment (C) via the "Import Wizard", Origin does not allow to do in this way!

Anybody can help? Thank you very much!

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