Network Automation Software We are currently migrating this forum
over to our HelpSystems domain. Please
post all new threads in our new
HelpSystems Community Portal.
Post to the HelpSystems Forum
You are not currently logged on. You must be logged on in order to post. Log on
Or Create a new account
AutoMate Discussion
Decrease font size
Increase font size
Topic Title: Rename multiple files using variables
Topic Summary: I can't seem to get dynamic file renaming going!
Created On: 05/08/2014 08:35 AM
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
View similar topics View similar topics
View topic in raw text format. Print this topic.
 05/08/2014 08:35 AM
User is offline View Users Profile Print this message

Author Icon
JonDombrowiak
n00b (>6 posts)

Posts: 5
Joined: 02/17/2014

This seems like a rather simple task but so far is eluding me.

Problem:  I have a directory with numerous txt files named as follows:

abcd.MD.NEWHIRE.txt

abcd.OH.NEWHIRE.txt

abcd.WV.NEWHIRE.txt

I want to rename each file by adding a datetime stamp IN THE MIDDLE, as follows:

abcd.MD.NEWHIRE_20140101.txt

abcd.OH.NEWHIRE_20140101.txt

abcd.WV.NEWHIRE_20140101.txt

I have  a dataset capturing all of the text file names and have built a variable to construct the NEW file name...

%left(ds.Filename,17)%_%theDateTime%.txt

...so far, so good.

But try as I might I cannot get the Rename to work.  It either gives me Operand/operator type mismatch.

Any help appreciated, everything else works well, but I can't get this simple task working!



 Category Survey
AutoMate 9 version: 9.0.4
Windows version: Windows 7



Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)
 05/08/2014 09:40 AM
User is offline View Users Profile Print this message

Author Icon
JonDombrowiak
n00b (>6 posts)

Posts: 5
Joined: 02/17/2014

Solved with workaround. 

I could get it to work by looping through the files in a directory, but I really wanted to use a Dataset so I could limit it to *.txt files.

Using the dataset already built, rather than dynamically renaming each file by splitting the path and file name and then concatenating them back together,  I used nested LEN in the LEFT function to rename the WHOLE path and file name, then passed that to the rename.

 

There has to be a more elegant solution, but this works.



 Category Survey
AutoMate 9 version: 9.0.4
Windows version: Windows 7



Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)
 05/08/2014 11:15 AM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

Jon,
there is no escape from a loop as you did.
The Left/Len expression is OK
Another possibility is %Replace(ds.FullName,".txt","_" & thedatetime & ".txt")%
It avoids the Len, the -4 and the 17, but the end result is the same.

 Category Survey
AutoMate 9 version: 9.0.5
Windows version: Windows 7


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
 05/08/2014 06:09 PM
User is offline View Users Profile Print this message

Author Icon
JonDombrowiak
n00b (>6 posts)

Posts: 5
Joined: 02/17/2014

Thanks, Jean, good tip!

Yeah, sorry, I didn't copy the whole task, only the relevant part.

There's some additional steps before the loop repeats.

Thanks again!



 Category Survey
AutoMate 9 version: 9.0.4
Windows version: Windows 7
 05/09/2014 12:26 AM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

You're welcome, Jon.

 Category Survey
AutoMate 9 version: 9.0.5
Windows version: Windows 7


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
Statistics
18258 users are registered to the AutoMate Discussion forum.
There are currently 0 users logged in.
The most users ever online was 5551 on 01/08/2018 at 11:11 AM.
There are currently 1341 guests browsing this forum, which makes a total of 1341 users using this forum.

FuseTalk Enterprise Edition v4.0 - © 1999-2020 FuseTalk Inc. All rights reserved.

Sitemap Network Automation Software Blog