Intelligent Automation & Macro Software  

Go Back   Automation Anywhere, Inc. Forums > Products Zone > Automation Anywhere
Register FAQ Search Today's Posts Mark Forums Read

Automation Anywhere Post messages and questions related to Automation Software here.


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-29-2007, 12:36 AM
zaguber zaguber is offline
Junior Member
 
Join Date: Jul 2007
Posts: 21
Default Last 3 characters from filename

Hi ,

I would like to take the last 3 charecters from a filename , For example my

filename is 001-002345-ABC.TIF . I would like to extract ABC from the filename .

Thanks

Syed
Reply With Quote
  #2 (permalink)  
Old 08-30-2007, 03:03 AM
forumsupport forumsupport is offline
Senior Member
 
Join Date: Apr 2007
Posts: 1,342
Default Re: Last 3 characters from filename

Hello,

You can easily leverage functionality of Excel to automate your task. You can use Mid() function of excel to extract the characters from a text string, given a starting position and length.

We have also attached a sample task (Last3Char.atmn) for your convenience.

Copy it under location: My Documents\Automation Anywhere\Automation Anywhere\My Tasks.

You can make changes in it according to your requirement for e.g. instead of ‘001-002345-ABC’ you can use filename also, you can run this task directly.


Hope that helps.
Attached Files
File Type: atmn Last3Char.atmn (8.7 KB, 17 views)
Reply With Quote
  #3 (permalink)  
Old 08-31-2007, 11:14 AM
helpermonkey helpermonkey is offline
Junior Member
 
Join Date: Aug 2007
Posts: 1
Default Use Windows, Its faster

Windows batch scripts can do simple string manipulation for you without the need to run (or buy and install) a large program like Excel.
Depending on how you want to interface with this data, this method may be useful.

Below is a screen capture showing a small sample of what you can do quickly and easily with batch scripts. You just need to be able to access the output of the command-line "echo." statements or redirect the output of the echo statements to a file using the syntax
echo.your text here >filename

The lines that start with c:\testdirectory> show what I typed in (I typed the stuff that comes after the '>').
The lines immediately following my commands are the returned values.

Here's the screen cap:

c:\testdirectory>set avariablename=001-002345-ABC.TIF

c:\testdirectory>echo.%avariablename:~-3%
TIF

c:\testdirectory>echo.%avariablename:~1,-3%
01-002345-ABC.

c:\testdirectory>echo.%avariablename:~1,-4%
01-002345-ABC

************************************************** ***
Here's a slightly more sophisticated approach that does more to show off the possibilities than anything else.
I'm going to write a short program on the fly. The funny thing is that creating a whole program to do the work for you, then running it and deleting it is still faster than opening Excel.

By the way, the ^Z is control+Z.
************************************************** ***

c:\testdirectory>copy con shortprog.bat
@ECHO OFF
echo.%~p1 is the path
echo.%~n1 is the name
echo.%~x1 is the extension
echo.%~n1%~x1 is the name plus the extension
echo.type "for /?" at the command prompt for more information
^Z
1 file(s) copied.

************************************************** ***
So I just created a file that is also a program, and I did it all with keystrokes.
Now I'll run the program, passing in our variable "variablename".
When you want the value of a variable, enclose that variable's name in %s
The "@ECHO OFF" suppresses my actual commands from being echoed to the screen, so that only the output of the commands shows.
************************************************** ***

c:\testdirectory>shortprog %avariablename%
\testdirectory\ is the path
001-002345-ABC is the name
.TIF is the extension
001-002345-ABC.TIF is the name plus the extension
type "for /?" at the command prompt for more information

c:\Documents and Settings\helpermonkey>


************************************************** ***
In short, if you open a cmd.exe window and send these two commands:

set tempstr=thestringyouwanttochop
echo.%tempstr:~1,-4%


the resulting text will be echoed to the screen for you to capture.

Personally, I would advocate the approach where you make a small batch program on the fly (shortprog.bat), because that way Windows determines what the extension is and can remove it for you, whether the extension is exactly three letters or not.
It runs very quickly, and its a good alternative if you want to run it on a PC that doesn't have Excel installed.

Hope this helps!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -7. The time now is 08:08 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0 ©2007, Crawlability, Inc.
Copyright © 2003-2011 Automation Anywhere, Inc. All rights reserved