Preserve the file name while writing to a file

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

intl_sp

Posts: 11
Joined: Wed Oct 01, 2014 8:49 am

Post by intl_sp » Mon Oct 13, 2014 3:49 pm
I am working on a project that takes in CSV files generated in LINUX. These files generated in LINUX have formatting where the record/row separator is a line feed, which doesn't match our requirement. Hence I am reading these files again through GoAnyWhere Director and while writing them I change the formatting to CarriageReturn + LineFeed so that these can be picked up by the next job without throwing any error.

Although I am successful in doing so, the only challenge I am facing is that of preserving the file name. Is there any way I could use the original file name while writing these files?

The following is what I have till now :
Code: Select all
<project name="readCSV_WriteCSV" mainModule="Main" version="2.0">

	<module name="Main">

		<createWorkspace version="1.0" />


		<setVariable label="Init:  FTPError" name="FTPError" value="0" version="2.0" />


		<ftps label="Source" resourceId="ftps test" outputSessionId="Src_SessionID" version="1.0" logLevel="debug" onError="setVariable:FTPError=1">
			<get label="Get all files from folder" destinationDir="${system.job.workspace}" whenFileExists="skip" destinationFilesVariable="Loc_files" numFilesDownloadedVariable="NoFiles" processedSourceFilesVariable="Rmt_files">
				<fileset dir="/trial/" recursive="false" />
			</get>
		</ftps>


		<readCSV outputRowSetVariable="csvRow" fieldDelimiter="comma" skipFirstRow="false" recordDelimiter="LF" textQualifier="none" processedInputFilesVariable="processedFiles" version="1.0" logLevel="debug" onError="continue">
			<fileset dir="${system.job.workspace}" recursive="false" />
		</readCSV>


		<writeCSV inputRowSetVariable="${csvRow}" outputFile="resource:smb://Alpha//COMPANYNAME_status_${CurrentDate()}.csv" whenFileExists="rename" fieldDelimiter="comma" includeHeadings="false" recordDelimiter="CRLF" textQualifier="none" version="1.0" logLevel="debug" onError="continue" />

		<deleteWorkspace version="1.0" />


		<exitProject version="1.0" />

      </module>

     <module>

           <routine to send Emails on FTP error> </routine>

     </module>

</project>
		

Support_Rick

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

Post by Support_Rick » Mon Oct 13, 2014 4:46 pm
Try doing the following (in pseudo terms)

Your FTPS Get for a FileSet value indicates that you can expect Multiple files to be downloaded. You must treat it as such... I would treat these files individually (even if I'm only expecting 1 file)
Code: Select all
FTPS | Get *
   From /trial/
   To Workspace
   DestFileVar = Loc_Files

ForEach ${Loc_Files} / ThisFile
   searchAndReplace 
      inputFile="${ThisFile}" 
      outputFile="${ThisFile:name}_status_${CurrentDate()}.csv" 
      searchFor="\n" 
      replaceWith="\r\n" 
      outputFilesVariable="NewLocFile"
      whenFileExists="rename"

   Copy
      SourceFilesVariable = ${NewLocFile}
      DestinationDir = "resource:smb://Alpha"

EndForEach
In this instance ... ${ThisFile:name} will give you the original file name
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696

intl_sp

Posts: 11
Joined: Wed Oct 01, 2014 8:49 am

Post by intl_sp » Wed Oct 15, 2014 12:36 pm
thanks! that helped...
3 posts Page 1 of 1