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
 Change multiple book names
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Clairekun

Germany
175 Posts

Posted - 01/31/2013 :  05:05:22 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin 9
Operating System: Windows 7

Hello,

First of all I know very little about programming, so please explain things to me as if I were a child. I have been trying to find a way to rename imported files. I usually work with over 50 files at once, so doing it manually can get very frustrating.

The file name itself contains more information that what I would want the books to show, for example:

uselessinfo_23_moreuselessinfo.asc

I would like the book name to be "23cm", as in "measurement data + units".

I have found ways to hide file extension, so it is not necessary for you to tell me how.

greg

USA
1378 Posts

Posted - 01/31/2013 :  3:09:58 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If you are using ASCII Import, then the (Re)Naming section lets you specify which characters to grab out of a filename to use as Workbook or Worksheet name.
For
uselessinfo_23_moreuselessinfo.asc
you could use
Trim Filename From = 13
Trim Filename To = 14
for the Sheet name to get a sheet named '23', but since you want 'cm' appended and since I suspect the leading text "uselessinfo_" may actually vary in length, then some other solution is needed.

Setup your ASCII Import to NOT rename anything and use this script :
// BEGIN SCRIPT
doc -ef W {
string str$ = %(%H, @W,SYSTEM.IMPORT.FILENAME$);
str$ = str.GetToken(2,'_')$;
win -r %H %(str$)CM;
}
// END SCRIPT
which will loop over all worksheets in the current folder, find the actual filename, grab the part of the name delimited by '_' and add CM and use that to rename the Workbook.

To use:
After importing, copy and paste the script into the Command Window and press Enter.
Origin will prefix an 'A' since Workbook names should not begin with a number and will prompt you if it encounters a duplicate name.

Note that if your naming convention is a bit more complicated, you may need to learn some programming to customize to your needs.
Go to Top of Page

Clairekun

Germany
175 Posts

Posted - 02/06/2013 :  07:39:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for your help. I combined what you told me with other functions I found and could finally get almost what I wanted. The final result is:

A23cm

However, since Workbook names need to have a prefix, I would like the name to something like:

L=23cm or L-23cm (since, in this case, I would be using length units)

So that I can find the number more easily with only a glance. I have tried the replace and insert functions, but don't seem to get them to work.

However, if this is not possible, making the prefix lowercase would suffice.

Thanks again, you were of great help.
Go to Top of Page

greg

USA
1378 Posts

Posted - 02/07/2013 :  3:08:41 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
string str;
str$ = 23;
str.INSERT(1,"L="); // There's an INSERT method
str$ = %(str$)cm; // Use substitution to append
str$ =;

turns "23" into "L=23cm".

as does this code:

string str1,str2;
str1$ = 23;
str1.INSERT(1,"L="); // There's an INSERT method
str2$ = cm;
str1$ = str1$+str2$; // concatenate strings by addition
str1$ =;
Go to Top of Page

Clairekun

Germany
175 Posts

Posted - 02/26/2013 :  05:29:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
In the end, I applied replace method, which I had tried before with no luck. My mistake was in typing the whole word lowercase, but it worked as soon as I typed str.Replace .

Many thanks!
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