Automic Workload Automation

  • 1.  File Transfers into sub-directories

    Posted Apr 28, 2015 02:37 PM
    Hi All, this is my first post, but I've recently stepped into the role of a UC4 admin at my company. So far, it seems like a really amazing piece of software so I'm looking forward to learning more about it.

    Currently, I'm attempting to write a script which will look in a directory and transfer the files from it to sub directories on a different agent based on sub-strings within the file names.

    For an example, I have directory C:\pictures which has two files in it, p0576410.jpg and p0871254pic.jpg. I'm writing a script which will move these files into sub-directories (on a different agent) C:\pictures\057 and C:\pictures\087 so I'm using the 2-4 character strings of the file names. The script needs to look at the 2-4 characters and then move the file into the subdir automatically, if the subdir doesn't exist then it needs to create it according to the 2-4 character string. It will always be the 2-4 character string also.

    At this point, I have figured out how to create the script such that it will only take the 2-4 character string by using the MID() command. And I know that in using a file transfer object, I can put in the destination path, the variable I'm using to define the substring (so in the destination path for JOBF, I can put C:\pictures\&substring# but what my script seems to do is us the very last substring and only create a subdir based on that.

    So going back to my previous example, it would just create C:\pictures\087 and then put both files in that subdir.

    Here is my code so far: (For reference, VARA.FILELIST.MRA, is a list of file names exactly like the one in my previous example, but there are 9)

    :  DEFINE &pnum#, String
    :  set &fid# = PREP_PROCESS_VAR(VARA.FILELIST.MRA)
    :  PROCESS &fid#
    :  SET &file# = GET_PROCESS_LINE(&fid#)
    :  PRINT &file#
    :  SET &pnum# = MID(&file#, 2,4)
    :  PRINT "NEXT LINE IS PNUM"
    :  PRINT &pnum#
    :ENDPROCESS

    This is in the "process" tab of a JOBF object, fyi, and in the destination path, it is C:\pictures\&pnum. It's almost like I need to loop it so that it transfers each file individually, but I can't imagine that's right let alone how I could do that...

    Any help would be much appreciated!




  • 2.  File Transfers into sub-directories

    Posted Apr 28, 2015 04:55 PM
    Hey Bertie, welcome to the software and community! I'm writing this assuming you're using V9, V10 or V11. I would hold off on using JOBF jobs unless transferring files between different OS's or between like a DMZ and internal network that you need different credentials for. If you're just going from one windows server to another, using a MOVE dos command is easier to deal with. Are you loading your vara up with the files that exist in the folder or is it always going to be the same 9?



  • 3.  File Transfers into sub-directories

    Posted Apr 28, 2015 08:10 PM
    Bertie:

    Since you appear to be transferring files between Agents then I might suggest that you review this thread.  I believe that, in principle, it deals with similar functionality.  Hope it helps and as Jim said, welcome.


  • 4.  File Transfers into sub-directories

    Posted Apr 29, 2015 08:20 AM
    Jim_Griffith_8234 - Hi Jim, thank you for the welcome! The vara will not always be those 9, those are just test files. Eventually, I want to be able to run this job and specify a path and have it just pull all the files from the directory specified and transfer them to another specified directory but also is breaking down the filename and using the 2-4 substr to create subdirs. To answer your question in short, it will have to deal with more/different files. Hope that was helpful!

    I'm also currently still learning, I literally stepped into UC4 about 2 days ago so I'm currently reading the manuals on the basics/scripting language so I'm guessing that'll help immensely. (for reference, currently using V9)


  • 5.  File Transfers into sub-directories

    Posted Apr 29, 2015 08:21 AM
    Mark_Hadler_430 - Hi Mark, also thank you for the welcome! That looks to be very similar to what I'm trying to do, I'll read through it, thanks for the link!


  • 6.  File Transfers into sub-directories

    Posted Apr 29, 2015 09:14 AM
    Bertie, You wouldn't necessarily need to load the files into a vara. You could do something like this in the process tab. 

    :SET &PPF# = PREP_PROCESS_FILENAME('<SERVER>', 'c:\pictures\*.jpg',,,,'COL=LENGTH','LENGTH_TAB="12=PATH, 100=FILE"')
    :PROCESS &PPF#
    :   SET &FILE# = GET_PROCESS_LINE(&PPF#, FILE)
    :   PRINT &FILE#
    :  SET &pnum# = MID(&file#, 2,4)
    :  PRINT "NEXT LINE IS PNUM"
    :  PRINT &pnum#
    !
    MOVE c:\pictures\&FILE# c:\pictures\&PNUM#\
    !
    :ENDPROCESS

    The prep_process_filename will discover the .jpg files in the c:\pictures directory, pull the PNUM that you want, and move them all in one step. No need to load them into a vara unless you have multiple jobs using the files. You could also use the FILELIST vara in place of the PREP_PROCESS_FILENAME and do a prep_process_vara. Both will end up with the same result. 


  • 7.  Re: File Transfers into sub-directories

    Posted Jul 03, 2018 01:54 PM

    Hi Jim,

     

    I used your script for file transfer. Wrote the lines of code in process tab of a windows job. The issue is that the job runs fine even if there is no file present in the folder which is as per the definition of script function PREP_PROCESS_FILENAME as I read it. What should be done if we want the job to fail if it does not find any file?

     

    Thanks!



  • 8.  File Transfers into sub-directories

    Posted May 04, 2015 12:14 PM
    Hi Jim,

    Oh! Let me give that a try...

    Sorry I didn't see this sooner! I've been trying to figure it out a different way using the cmd line commands...

    I'll try that out. Thanks!


  • 9.  File Transfers into sub-directories

    Posted May 04, 2015 02:11 PM
    That did it! I got it working, I had to tweak it so it would create the directories but even so, thank you!


  • 10.  File Transfers into sub-directories

    Posted May 04, 2015 02:31 PM
    Yea I would have thrown a MD command right before the move or created another step to make the directory then move the file. Glad that worked for you!