Automic Workload Automation

Expand all | Collapse all

CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

  • 1.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-13-2017 06:08 AM
    HI All.

    I have never posted here before so apologies if this is the wrong area. 

    I have a process in AE10 to archive and add a date and timestamp to each file that lands in a folder before onward transfer.

    However, I am struggling to find within the Help F1 documentation how I can add a sequential file number to each file and for AE10 to know exactly what the last URN was to add the next one.   

    Has anyone done or achieved this previously?  

    This is my current Process code below.  Any advice would be welcomed....thanks
    Justin Cookee
    cookeej@cpwplc.com


    ! Change each file within this folder with the date and time
    ForEach ($file in $files){
       $filename = $file.FullName;
       $name = [io.path]::GetFileNameWithoutExtension($filename);
       $FileExtension = $filename.Split('.')[1];
       $date = Get-Date -format yyyyMMdd;
       Rename-Item $file "$($name)_$($date)_$($time).$($FileExtension)"
       Write-Output "$($name)_$($date)_$($time).$($FileExtension)"}


  • 2.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-13-2017 02:00 PM
    Assuming you are in PowerShell;
       To initialize your counter; $MyCounter = 0
       To increment your counter by one; $MyCounter++

    But PowerShell variables are not natively available to AE.  If you need your AE script to know how many files were processed by your PowerShell process, there are two ways to do it.  But both methods require picking up the results in a post-process script.






  • 3.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-16-2017 07:48 AM
    Hi Pete.

    Many thanks indeed for your assistance and answer.

    Yes I am using a powershell archive process. 

    Can you list the two post process ways to achieve this that you mention?

    I hope this is the answer I need to achieve my test case. 

    thank you again.
    Justin


  • 4.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-16-2017 02:14 PM
    I personnally assume its easier in Automic script

    to get this correct, you want to check all files within a folder (lets say every txt file) and add hmm what - a timestamp as in your PS example or a incremental number?

    pls tell more how is the filenam being created and how starts the number, does it start every execution of the job with zero or has the value to be stored within automic?

    I understood:
    You want to create a job that searches for all file (matching s pattern) in a directory and renames al the files to filename[ascending number].


  • 5.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-17-2017 04:43 AM
    HI Wolfgang.

    I already have a pre-process to pick up a file, archive it with a date and time and then move it across an encrpyted vpn..  

    I want to add to a file number to be before the date time stamp and then always add the next number by knowing what the previous number was. 

    I dont know if thats possible so thought best to ask as I havent been able to assign mycounter++ correctly to do this.

    Thanks
    Justin


  • 6.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-17-2017 01:00 PM
    I agree with Wolfgang that taking PowerShell out of the equation would be preferable.  I cobbled together this piece of code to grab a list of TXT files and rename them to include a counter.  Its not pretty... but it works.


    :SET &HND# = PREP_PROCESS_FILENAME("&$AGENT#","\\t11946\Public\UC4_Util_Testing\file*.txt","Y",,,,"UC_LOGIN=LOGIN.UC4")
    :set &MyCounter# = 0
    :PROCESS &HND#
    :   SET &LINE# = GET_PROCESS_LINE(&HND#)
    :   PRINT &LINE#
    :   set &MyCounter# = &MyCounter# + 1
    :   set &MyCounter# = substr(&MyCounter#,12)
    :   set &pos1# = str_find(&Line#,".txt")
    :   set &pos1# = &pos1# - 1
    :   set &REPL# = substr(&LINE#,1,&pos1#)
    :   set &pos1# = str_find_reverse(&REPL#,"\")
    :   set &pos1# = &pos1# + 1
    :   set &REPL# = substr(&REPL#,&pos1#)
    :   set &REPL# = "&REPL#_&MyCounter#.txt"
    :   print &REPL#
    ren "&LINE#" "&REPL#"
    @set retcode=%errorlevel%
    @if NOT %ERRORLEVEL% == 0 goto :retcode
    :ENDPROCESS 



  • 7.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-18-2017 04:32 AM
    small add to Petes Solution (would also be my first joice):

    if you want to store the counter number use put_var at the end and get_var on the start of the script


  • 8.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-18-2017 04:51 PM
    here is my Plan B ( WIN JOB )

    :SET &AGENT# = "V112_WIN01"
    :SET &MYCOUNTVARA# = "VARA.FILECOUNT"
    :SET &EXTENSION# = ".txt"
    :SET &WORKDIR# = "C:\uc4\V112\Workdir\*"

    :SET &LAST_COUNTER_VALUE# = GET_VAR (&MYCOUNTVARA#,"LASTFILECOUNT")
    :SET &COUNTER# = &LAST_COUNTER_VALUE#
    :P "LAST VALue from VARA: &COUNTER#"

    :SET &HND# = PREP_PROCESS_FILENAME(&AGENT#,"&WORKDIR#&EXTENSION#","Y",,,,"UC_LOGIN=@LOGIN.DEFAULT")
    :PROCESS &HND#
    :   SET &LINE# = GET_PROCESS_LINE(&HND#)
    :   SET &FILENAMEPOS# = 4
    :   PRINT "Old Filename: &LINE#"
    :   SET &EXT_POS# = STR_FIND(&LINE#,&EXTENSION#)
    :   SET &EXT_POS# = SUB (&EXT_POS#,1)
    :   SET &PATH_WITHOUT_EXT# = MID(&LINE#,1,&EXT_POS#)
    :   SET &LASTBACKSLASH_POS# = STR_FIND_REV(&PATH_WITHOUT_EXT#,"\")
    :   SET &LASTBACKSLASH_POS# = ADD(&LASTBACKSLASH_POS#,1)
    :   SET &JUSTFILENAME# = MID(&PATH_WITHOUT_EXT#,&LASTBACKSLASH_POS#,)
    :   SET &NEWFILENAME# = "&JUSTFILENAME#_&COUNTER#&EXTENSION#"
    :   PRINT "modified new filename: &NEWFILENAME#"
    :   PRINT "-----------------------"
    ren &LINE# &NEWFILENAME#
    @set retcode=%errorlevel%
    @if NOT %ERRORLEVEL% == 0 goto :retcode
    :   SET &COUNTER# = ADD(&COUNTER#,1)
    :   SET &COUNTER# = FORMAT(&COUNTER#)
    :ENDPROCESS

    Report:
    2017-01-18 21:44:45 - U00020408 LAST VALue from VARA: 8
    2017-01-18 21:44:45 - U00020408 Old Filename: C:\uc4\V112\Workdir\test1.txt
    2017-01-18 21:44:45 - U00020408 modified new filename: test1_8.txt
    2017-01-18 21:44:45 - U00020408 -----------------------
    2017-01-18 21:44:45 - U00020408 Old Filename: C:\uc4\V112\Workdir\test2.txt
    2017-01-18 21:44:45 - U00020408 modified new filename: test2_9.txt
    2017-01-18 21:44:45 - U00020408 -----------------------
    2017-01-18 21:44:45 - U00020408 Old Filename: C:\uc4\V112\Workdir\test3.txt
    2017-01-18 21:44:45 - U00020408 modified new filename: test3_10.txt
    2017-01-18 21:44:45 - U00020408 -----------------------
    2017-01-18 21:44:45 - U00020408 Old Filename: C:\uc4\V112\Workdir\test4.txt
    2017-01-18 21:44:45 - U00020408 modified new filename: test4_11.txt
    2017-01-18 21:44:45 - U00020408 -----------------------
    2017-01-18 21:44:45 - U00020408 Old Filename: C:\uc4\V112\Workdir\test5.txt
    2017-01-18 21:44:45 - U00020408 modified new filename: test5_12.txt
    2017-01-18 21:44:45 - U00020408 -----------------------


    Count Vara (for storing the latest value for the counter)
    kjkei36psdwy.jpg

    Files before change:
    2uahm19925sc.jpg

    Files after change:
    k4l4m69avipt.jpg







  • 9.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-26-2017 11:59 AM
    Thank you Wolfgang.





  • 10.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-27-2017 09:34 AM
    welcome :-)


  • 11.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-30-2017 09:40 AM
    Hi Wolfgang.

    Will this only with .txt or can It work with .CSV and .XLS? 

    Regards
    Justin



  • 12.  CAN AE10 give each renamed file an iterative sequential number from 1 -9999?

    Posted 01-30-2017 12:23 PM
    You can change this line of code to make it work with different file types;

    :SET &EXTENSION# = ".txt"