T O P I C R E V I E W |
neutrondude |
Posted - 12/13/2010 : 10:24:51 AM Origin Ver. and Service Release (Select Help-->About Origin): Operating System: 8.1 , Win7
Dear all, Im using the filter option with a script to import and manipulate multiple files under origin. I have the following script commands to delete the first characters, but now I have long filenames where I would like the first x and and last y characters to be removed. Could anyone provide me with a easy way to do it?
%A = page.info.system.import.filename$; // get filename %A = %[%A,#1,.]; // strip extension length = %[%A]; //length of string %A = %[%A,length-4:length]; // strip all but last 4 characters win -r %H %A; // rename worksheet delete -v length
Thank you very much in advance!
|
5 L A T E S T R E P L I E S (Newest First) |
vincenth |
Posted - 12/16/2010 : 12:09:06 PM I tried your code and it worked fine for me. I think we can work in parallel here ...
Can you send us your filter (and which SR of 8.1), in case something is up there? (tech@originlab.com, attn: Vince, or follow the link at the top-right of this page)
Also, if you are running SR0--SR2, try patching to SR3, and try it again (in case of some earlier script bug): http://www.originlab.com/Index.aspx?go=SUPPORT/ServiceReleases
In addition, I noticed that the error you get cites "AA," which is the name of one of the variables I defined in my sample code. Might my code have gotten mixed up with yours?
Vince |
neutrondude |
Posted - 12/16/2010 : 11:25:28 AM Dear Vince,
thanks a lot, I have tried the following code:
// Get filename to string string str$=page.info.system.import.filename$; // Remove extension str$=str.getfilename(1)$; // Get middle part by removing some chars from left and right // Look for more such functions in documentation str$=str.mid(11,5)$; // Rename worksheet with truncated string wks.name$=str$;
However, I cannot rename the file to what I want- it says:
"=page.info.system.import.filename$ string expression error! AA:failed to add variable to local stack!"
Best regards
|
vincenth |
Posted - 12/16/2010 : 10:38:52 AM Hi,
The mid function is defined such that mid(n,m) says give me m characters starting at position n, see the definition here:
http://wiki.originlab.com/~originla/wiki/index.php?title=Category:String_and_Characters_%28Labtalk%29
So the following script will get you what you want:
// I'm defining a string whereas you will have the name by import: string aa$="fr_xxxx_0_1491_ave_div_rebin.DAT";
// Define and assign the new string that you want: string cc$ = aa.mid(11,4)$ + aa.right(4)$;
// Confirm: type cc$; 1491.DAT
// Here is what you are currently getting, I guess: string bb$ = aa.mid(10,14)$; type bb$; _1491_ave_div_
Hope this helps.
Vince OriginLab Corp |
neutrondude |
Posted - 12/16/2010 : 10:23:16 AM Thanks a lot, but Im not sure I get it.
If I have file eg. called
fr_xxxx_0_1491_ave_div_rebin.DAT
I wanted to remove the first 10 characters and the last 14, i.e I want 1492.DAT as the filename. I tried the function: str$=str.mid(10,14)$;
thinking that it would remove everything except the characetrs 10-14, but it doesnt work. It simply takes the name of the worksheet and increment by one each time.
Could you please give me some more advice.
|
easwar |
Posted - 12/13/2010 : 11:49:14 AM Hi,
In version 8.0 onwards we have added better string processing, so you can rewrite your code as below:
// Get filename to string
string str$=page.info.system.import.filename$;
// Remove extension
str$=str.getfilename(1)$;
// Get middle part by removing some chars from left and right
// Look for more such functions in documentation
str$=str.mid(4,8)$;
// Rename worksheet with truncated string
wks.name$=str$;
Easwar OriginLab |
|
|