Page 1 of 1

Rearrange file name

Posted: Tue Oct 07, 2014 8:47 am
by kgough
I have a requirement to rename a file based on previous file name.
Is it possible?

For example
xx2014-10-07TEST.txt
will be renamed
xx07-10-2014tst.txt

I cannot use the current date function because I may have to process older files.

Re: Rearrange file name

Posted: Tue Oct 07, 2014 3:40 pm
by Support_Rick
kgough,

You're option here is to parse the original file name. Something like:

Set FYear = Substring( FName, 3, 4 )
Set FDay = Substring( FName, 8, 2 )
Set FMonth = Substring( FName, 11, 2 )

Then, create your new file name:

Set NewFile = ${ Concat( 'xx', FMonth, '-', FDay, '-', FYear, 'tst.txt' ) }

Re: Rearrange file name

Posted: Tue Oct 07, 2014 3:57 pm
by kgough
That is exactly what I want.
Should I run the "Set" commands by adding them as "Execute Native Command" steps?

Re: Rearrange file name

Posted: Tue Oct 07, 2014 4:11 pm
by Support_Rick
Not at all .. just use the SetVariable Task

<setVariable label="set FDay" name="FDay" value="${Substring( FName, 8, 2 )}" version="2.0" />

Re: Rearrange file name

Posted: Wed Oct 08, 2014 10:25 am
by kgough
When I try that I get an error:

<setVariable label="Set JJ-Day" name="JJ" value="${Substring( LocalFile, 24, 2 )}" version="2.0" />

Variable not found: Substring( LocalFile, 24, 2 )

My main project is Version 1, is that the problem?
Then if I switch to V2 I get an error in my ExecuteOnlyIf
executeOnlyIf="${myLocalFileCount} ge 1"

Re: Rearrange file name

Posted: Wed Oct 08, 2014 10:39 am
by Support_Rick
Ken,

Upgrading to version 2 will get you a bit more functionality with your Expression Wizard.

When editing the Version 1 project, click on the Upgrade button and convert to Version 2. Then, your Expression Wizard will give you the options you need for the Functions (Substring, Contains, etc)

Don't forget that the syntax of the command changes with this.

${var} eq 'x'

now becomes...

${ var eq 'x' }

Let us know if you have any other questions.

Re: Rearrange file name

Posted: Wed Oct 08, 2014 1:21 pm
by kgough
That worked.
Thank you very much!