Page 1 of 1

Copying a Directory

Posted: Tue Dec 06, 2016 5:10 pm
by Artis_Wright
I am sorry if there is a post regarding this already, however, I was unable to find it.

Basically what I want to do is copy a directory and place that copy someplace else. Here is my code. I am using a workspace because I plan to zip the file before copying the file from the workspace to its new home.
Code: Select all
 <project name="Copy Folder" mainModule="Main" version="2.0" logLevel="verbose">

	<module name="Main">

		<createWorkspace version="1.0" />


		<copy destDir="${system.job.workspace}" version="1.0">
			<fileset dir="C:\X\*">
				<wildcardFilter>
					<include pattern="*" />
				</wildcardFilter>
			</fileset>
		</copy>


		<copy destDir="C:\Y" version="1.0">
			<fileset dir="${system.job.workspace}" />
		</copy>


		<deleteWorkspace version="1.0" />


		<exitProject version="1.0" />

	</module>

</project>

Re: Copying a Directory

Posted: Tue Dec 06, 2016 5:27 pm
by Support_Rick
Artis,

You're close! :)

When selecting your fileList, just put the wildcard in the filter, like this:

<fileset dir="C:\X"\>

If you are getting ALL files from the folder, you do not have to specify the wildcard. Only use that when you're wanting something like *.csv or ABC*.txt.

So, I would use something like this instead:

<copy destDir="${system.job.workspace}" destinationFilesVariable="myFiles" version="1.0">
<fileset dir="C:\X"/>
</copy>

Then, use the variable ${myFiles} as input into your zip:

<zip inputFilesVariable="${myFiles}" outputFile="MyZippedFiles.zip" outputFileVariable="zipFile" version="1.0" />

Then, copy your zip file to another location:

Copy ${zipFile} to C:\DestLocation

Try it!

Re: Copying a Directory

Posted: Thu Dec 08, 2016 11:41 am
by Artis_Wright
Support_Rick wrote:
Artis,

You're close! :)

When selecting your fileList, just put the wildcard in the filter, like this:

<fileset dir="C:\X"\>

If you are getting ALL files from the folder, you do not have to specify the wildcard. Only use that when you're wanting something like *.csv or ABC*.txt.

So, I would use something like this instead:

<copy destDir="${system.job.workspace}" destinationFilesVariable="myFiles" version="1.0">
<fileset dir="C:\X"/>
</copy>

Then, use the variable ${myFiles} as input into your zip:

<zip inputFilesVariable="${myFiles}" outputFile="MyZippedFiles.zip" outputFileVariable="zipFile" version="1.0" />

Then, copy your zip file to another location:

Copy ${zipFile} to C:\DestLocation

Try it!
Guten Tag,

This worked perfectly but I have one more question. Is there a way I can have it copy the sub directories within the folder that I am copying as well as all of its contents as well? It copied the files just fine but it ignored the folders.

Thanks!

-Artis

Re: Copying a Directory

Posted: Thu Dec 08, 2016 1:01 pm
by Support_Rick
Where you set the fileset Dir (C:\X\) .. there's an option for Recursive... just set that value to true.

Re: Copying a Directory

Posted: Fri Dec 09, 2016 4:09 pm
by Artis_Wright
Thank you, this worked perfectly. It did not work at 1st in testing but I learned that there has to be a file in the folder for it to work.