Page 1 of 1

Copying to destination folders using a wildcard

Posted: Fri Aug 01, 2014 1:15 pm
by TViens
I am trying to create a standard project for use with monitors. The directory structure is consistent for all projects.
<project dir>/inbound //Source files are place here by external systems
<project dir>/archive
<project dir>/outbound_example1
<project dir>/outbound_example2
<project dir>/outbound_example3

What I am trying to accomplish in the project is to take all files from the inbound directory and copy them to the outbound directories using a wildcard, <project dir>/outbound_* as an example.

If this can be accomplished the inbound script can be used without modification for all inbounds as long as the directory structure is consistent.

Can a wildcard be used in the copy command?
Can this be done without a loop?

Re: Copying to destination folders using a wildcard

Posted: Mon Aug 04, 2014 4:34 pm
by Support_Rick
Ted,

This can be accomplished by using local file system commands to generate the Folder List into a Temporary File. Then, read that file to get the folder names and copy to them. In pseudo terms,

Execute Local command: ls -d * > workspace/DirList.txt
Read DirList.txt
ForEach Inbound File
ForEach DirList / ThisDir
Copy From Inbound -> ${ThisDir}
/ForEach
/ForEach

Hope this helps!

Re: Copying to destination folders using a wildcard

Posted: Tue Nov 04, 2014 2:34 pm
by TViens
A solution was developed for this. What this solution allowed me to do was to create new monitors using a template script so that I can add and remove FTPs with easy using a standard structure in the file system.

My original solution is shown below. Linoma software recently added functionality to allow for this design. This distribution script is also responsible for zipping, archiving, etc.
Code: Select all
<project name="Distribute Inbound Files to Outbound Directories" mainModule="Main" version="2.0" logLevel="verbose" threadSafe="true">
	<variable name="files" value="" description="FileList variable transferred from Monitor" />
	<variable name="projectDirectory" value="" description="Root folder to process" />

	<module name="Main">

		<createWorkspace label="temp_workspace" version="1.0" disabled="false" />


		<exec label="list directories" executable="/data/utilities/getOutboundDirs.sh" outputFileVariable="fileList" version="1.0">
			<arg value="${projectDirectory}" />
			<arg value="${system.job.workspace}" />
		</exec>


		<readFlatFile label="Read File - Directory List" inputFile="${system.job.workspace}/${dirListFile}" outputRowSetVariable="directoryList" recordDelimiter="LF" trim="both" version="1.0" disabled="false" />

		<forEachLoop label="Copy files to the outbound directories" itemsVariable="${directoryList}" currentItemVariable="currentDirectory" disabled="false">

			<copy label="Copy inbound files to outbound directories" sourceFilesVariable="${files}" destDir="${currentDirectory[1]}" whenFileExists="overwrite" version="1.0" />

		</forEachLoop>

		<move label="Move files to archive" sourceFilesVariable="${files}" destDir="${projectDirectory}/archive" suffix="_${CurrentTimestamp(&apos;yyyymmddHHmm&apos;)}" destinationFilesVariable="filesProcessed" version="1.0" />


		<tar label="Compress Archive Files" inputFilesVariable="${filesProcessed}" outputFile="${projectDirectory}/archive/Archive_${CurrentTimestamp(&apos;yyyyMMddhhmm&apos;)}.tar.gz" compress="true" version="1.0" disabled="false" />


		<zip label="Zip Archive Files" inputFilesVariable="${filesProcessed}" outputFile="${projectDirectory}/archive/Archive_${CurrentTimestamp(&apos;yyyyMMddhhmm&apos;)}.zip" version="1.0" disabled="true" />


		<delete inputFilesVariable="${filesProcessed}" version="1.0" />


		<deleteWorkspace label="temp_workspace" version="1.0" disabled="false" />

	</module>

	<description>The purpose of this project is to distribute inbound files to outbound directories based on the parameters passed in the monitor job configuration.</description>
	<variable name="dirListFile" value="dirList.txt" description="This variable holds the value of the file name containing the directory listing." />
</project>