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
 Origin Forum
 Delete/change characters in filename under import
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

neutrondude

Brunei
Posts

Posted - 12/13/2010 :  10:24:51 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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!

easwar

USA
1964 Posts

Posted - 12/13/2010 :  11:49:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

neutrondude

Brunei
Posts

Posted - 12/16/2010 :  10:23:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.

Go to Top of Page

vincenth

30 Posts

Posted - 12/16/2010 :  10:38:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - vincenth on 12/16/2010 10:39:20 AM
Go to Top of Page

neutrondude

Brunei
Posts

Posted - 12/16/2010 :  11:25:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

vincenth

30 Posts

Posted - 12/16/2010 :  12:09:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Edited by - vincenth on 12/16/2010 12:11:12 PM
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