determing folder based on date

Post any question you may have in regards to GoAnywhere MFT and let our talented support staff and other users assist you.
12 posts Page 1 of 2

ehersh

Posts: 56
Joined: Mon Sep 26, 2016 12:50 pm

Post by ehersh » Mon Nov 28, 2016 2:35 pm
I have this project. It is to pull all files over 60 days old and post them to an encrypted folder. I got that done. The issue is that they want the files posted into a year folder based on date. Example: I have 2 encrypted folders called 2015 and 2016. I am pulling files over 60 days old on January 10 2016 and placing them in folders which can be either 2015 or 2016 depending on the date file modified. I do know how to get the previous year in date format. The thing I am considering is what is the best way to put the files in the correct folder. For example I am pulling files over 60 days old. That means I will pull files older than November 11, 2015. For ease of explanation lets say that will only be November 10. I would like to put that in the 2015 folder. But when I run the job on 3/5/2016 I will want to put the files with a date stamp in 2016 into the 2016 folder. I would like to be able to do this without modifying the project every year. Any suggestions on how best to accomplish this?

Support_Rick

Support Specialist
Posts: 592
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Mon Nov 28, 2016 4:07 pm
Since you can get access to the date modifed on each file .. you can pull the YEAR from that value.

With that value (let's say ${fileYear} for example), then you can create that folder as needed.

Remember, when you designate a folder as an Encrypted Folder, any folders created BENEATH that folder will automatically be encrypted as well.

With that in mind, as you loop through the files, glean the ${fileYear} from the lastModifiedDate then create the folder (Make Directory) but, make sure you also change the "onError" to "continue"... that way, if the file year folder already exists, it ignores the error and continues on.

This way, it will create the folders you need as you need them.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696

ehersh

Posts: 56
Joined: Mon Sep 26, 2016 12:50 pm

Post by ehersh » Mon Nov 28, 2016 4:23 pm
ok but is what I am trying to do is when I pick up a file if the file was modified in 2015 then I want to put it in a 2015 folder if in 23016 then a 2016 folder. What do I do for that grab the year from the date modified and use it to find the correct folder to put it in?

Support_Rick

Support Specialist
Posts: 592
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Mon Nov 28, 2016 5:07 pm
Yes, just parse the YEAR from the lastModifiedDate of the file and then insert the file into the corresponding "folderYear".
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696

ehersh

Posts: 56
Joined: Mon Sep 26, 2016 12:50 pm

Post by ehersh » Tue Nov 29, 2016 3:59 pm
I am very close. The one issue I have is if I have files with date modified in the year 2015 and 2016 all in the same folder they all go to the 2016 year. However if I have the files from 2015 sitting alone in the folder they will go to the 2015 folder.
Code: Select all
project name="testencryptesh" mainModule="Main" version="2.0" logLevel="debug">
	<description>pull files over 60 days old</description>

	<module name="Main">

		<timestamp version="1.0">
			<format outputVariable="date" pattern="yyyy-MM-dd" dayOfMonth="-${sixty_days}" />
			<format outputVariable="YEAR" pattern="yyyy" />
			<format outputVariable="PREV_YEAR" pattern="yyyy" year="-1" />
			<format outputVariable="${system.currentdate}" />
		</timestamp>


		<createFileList label="archived files" fileListVariable="archived_files" numFilesFoundVariable="file_cnt" version="1.0" logLevel="debug">
			<fileset dir="<path to>/Eligibility/Production Files/834_CCA/Archive/${YEAR}" />
		</createFileList>

		<forEachLoop label="for each file" itemsVariable="${archived_files}" currentItemVariable="currentfile" />

		<setVariable label="vGet Date" name="get_date" value="${currentfile:lastModifiedDate}" version="2.0" disabled="false" />


		<setVariable label="vGet Year" name="get_year" value="${substring(get_date,1,4)}" version="2.0" disabled="false" />


		<copy destDir="<path to>/Eligibility/ARCHIVE ENCRYPTED FILES/${get_year}" preserveDate="true" processedSourceFilesVariable="encrypted_files" version="1.0" disabled="false">
			<fileset dir="<path to>/Eligibility/Production Files/Archive/${YEAR}">
				<dateFilter>
					<exclude from="${date}" to="${system.currentDate}" />
				</dateFilter>
			</fileset>
		</copy>

	</module>

	<variable name="sixty_days" value="60" description="Files older than this will be moved" />
</project>
Last edited by ehersh on Mon Jul 17, 2017 2:57 pm, edited 1 time in total.

Support_Rick

Support Specialist
Posts: 592
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Tue Nov 29, 2016 4:15 pm
FYI ...

THIS:
<forEachLoop label="for each file" itemsVariable="${archived_files}" currentItemVariable="currentfile" />

Is only going to give you the LAST item in the list.... none of your tasks are inside the loop.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696

ehersh

Posts: 56
Joined: Mon Sep 26, 2016 12:50 pm

Post by ehersh » Wed Nov 30, 2016 9:53 am
I tried it with everything in the loop. It loops through all the files with the year as 2015. I think I have my loop wrong because it will cycle through once send all 207 files to the 2015 folder on one file then cycle through to the second file and do the same.
Code: Select all
<project name="testencryptesh" mainModule="Main" version="2.0" logLevel="debug">
	<description>pull files over 60 days old</description>

	<module name="Main">

		<timestamp version="1.0">
			<format outputVariable="date" pattern="yyyy-MM-dd" dayOfMonth="-${sixty_days}" />
			<format outputVariable="YEAR" pattern="yyyy" />
			<format outputVariable="PREV_YEAR" pattern="yyyy" year="-1" />
			<format outputVariable="${system.currentdate}" />
		</timestamp>


		<createFileList label="archived files" fileListVariable="archived_files" numFilesFoundVariable="file_cnt" version="1.0" logLevel="debug">
			<fileset dir="<path to>/Eligibility/Production Files/834_CCA/Archive/${YEAR}" />
		</createFileList>

		<forEachLoop itemsVariable="${archived_files}" currentItemVariable="currentfile">

			<setVariable label="vGet Date" name="get_date" value="${currentfile:lastModifiedDate}" version="2.0" disabled="false" />


			<setVariable label="vGet Year" name="get_year" value="${substring(get_date,1,4)}" version="2.0" disabled="false" />


			<copy sourceFilesVariable="${archived_files}" destDir="<path to>/Eligibility/ARCHIVE ENCRYPTED FILES/834_CCA/${get_year}" preserveDate="true" version="1.0" disabled="false">
				<fileset dir="<path to>/Eligibility/Production Files\834_CCA\Archive\2016">
					<dateFilter>
						<exclude from="${date}" to="${system.currentdate}" />
					</dateFilter>
				</fileset>
			</copy>

		</forEachLoop>
	</module>

	<variable name="sixty_days" value="60" description="Files older than this will be moved" />
</project>

Support_Rick

Support Specialist
Posts: 592
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Wed Nov 30, 2016 10:30 am
I believe that on your "copy" task, you want to copy "currentFile" .. .not "archived_files".
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696

ehersh

Posts: 56
Joined: Mon Sep 26, 2016 12:50 pm

Post by ehersh » Wed Nov 30, 2016 2:42 pm
I did that, same thing. I do run it in debug mode, the current file name does not change until all 207 files are transferred. Then it wants me to hit next again it will increment to the next file name and remain there while all 207 files transfer, then will do the same for the 3rd file etc.
Code: Select all
<project name="testencryptesh" mainModule="Main" version="2.0" logLevel="debug">
	<description>pull files over 60 days old</description>

	<module name="Main">

		<timestamp version="1.0">
			<format outputVariable="date" pattern="yyyy-MM-dd" dayOfMonth="-${sixty_days}" />
			<format outputVariable="YEAR" pattern="yyyy" />
			<format outputVariable="PREV_YEAR" pattern="yyyy" year="-1" />
			<format outputVariable="${system.currentdate}" />
		</timestamp>


		<createFileList label="archived files" fileListVariable="archived_files" numFilesFoundVariable="file_cnt" version="1.0" logLevel="debug">
			<fileset dir="<path to>/Eligibility/Production Files/834_CCA/Archive/${YEAR}" />
		</createFileList>

		<forEachLoop itemsVariable="${archived_files}" currentItemVariable="currentfile" currentIterationVariable="number">

			<setVariable label="vGet Date" name="get_date" value="${currentfile:lastModifiedDate}" version="2.0" disabled="false" />


			<setVariable label="vGet Year" name="get_year" value="${substring(get_date,1,4)}" version="2.0" disabled="false" />


			<copy sourceFilesVariable="${currentfile}" destDir="<path to>/Eligibility/ARCHIVE ENCRYPTED FILES/834_CCA/${get_year}" preserveDate="true" version="1.0" disabled="false">
				<fileset dir="<path to>/Eligibility/Production Files\834_CCA\Archive\2016">
					<dateFilter>
						<exclude from="${date}" to="${system.currentdate}" />
					</dateFilter>
				</fileset>
			</copy>

		</forEachLoop>
	</module>

	<variable name="sixty_days" value="60" description="Files older than this will be moved" />
</project>

Support_Rick

Support Specialist
Posts: 592
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Wed Nov 30, 2016 2:46 pm
With an answer here and there, it's fine.. but, this is getting into consulting time as it's taking time to go through and decipher what it is you're trying to do and coming up with a solution as to what needs to be done.

Please contact our support group and schedule some time if you need additional help with this.

Thanks!
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
12 posts Page 1 of 2