Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


Madeleine
2013-08-11T15:39:43Z
Hi, I need a job like this:

1. File Copy Task: Copy most recent file from source folder to destination folder.
2. Execute Task: Run a script with this file as command line arg

So far I have a Copy Files task with a file filter to copy only files created within the last hour of the job running - I know the file creation frequency so I know this will be sufficient to get the most recent file. (If there is a better way to do this please tell me !)

Now for the Execute task, to get the destination path to pass as command line arg, I think I need to use the VisualCron variable {TASK(Active,Result.CopiedFilesDestination)}
but I expect there to be exactly one file there.

Question is, how to extract the path of that single file from the list?
Do I need to use a loop with a single iteration?
Or is there a way to reference the list element directly?

Thanks
Madeleine
Sponsor
Forum information
KJDavie
2013-08-12T02:43:09Z
Hi Madeleine & Welcome,

Short Answer, Perhaps for safety just use LastLine (Version 7) on a Set Variable Task to take the last result (a single result for safety) and set it to a variable on the next task:

{STRING(LastLine|{TASK(PrevTask,Result.CopiedFilesDestination)})}

You can then use the Variable as a parameter to your script.

Per above, the order of the FileCopy / File List if you ever get more than 1 result will be alpha order not last written ?

--- *** ---

Plan (b)

Key to your issue is controlling the File selection as you want the last file (written ?)

File List will show you the files, and file copy using the parameters you are *should* give you the single result you are looking for, but ordering is a feature request I think (Alpha sort at present ?)

One Suggestion is Use a Short Powershell Line + a VisualCron Powershell Task to find what you want.

Sorry in advance if you know powershell, I have verbosed out an example based on something else I had as we are using multiple pipes here

-- snip --
# List the Files "Get-Childitem"
# Nominate Directory (Or Use VisualCron Variable Here)
# Not Subdirectories "?{-not $_.PsIsContainer}"
# Sorted by Last File Written "Sort LastWriteTime"
# Get the last file "Select -Last 1"
$GetLatestFile = Get-Childitem "C:\Batch" | ?{-not $_.PsIsContainer} | Sort LastWriteTime | Select -Last 1

# Write Output Result to return to VisualCron for use in later tasks
# FullName = Directory + FileName
Write-Output $GetLatestFile.FullName
-- snip --

You can then use VisualCron Path Variables to slice and dice that if you wish.

Sort in Powershell has a lot of flexibility so if this (LastWriteTime) isn't to your taste perhaps one of the other file attributes will hit the spot.

http://technet.microsoft...us/library/ee176968.aspx 

We have had a lot of success with VisualCron tasks, supplemented with some limited powershell, replacing existing long form scripts (in powershell and other legacy script languages - cmd / bat).

Good Luck !

Kevin
KJDavie attached the following image(s):
Madeleine
2013-08-12T07:25:47Z
Thanks Kevin, we don't yet have version 7. The Powershell solution looks interesting - we will look into it further.
Great, thanks
Madeleine
Scroll to Top