Page 1 of 1

Preserve the file name while writing to a file

Posted: Mon Oct 13, 2014 3:49 pm
by intl_sp
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>
		

Re: Preserve the file name while writing to a file

Posted: Mon Oct 13, 2014 4:46 pm
by Support_Rick
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

Re: Preserve the file name while writing to a file

Posted: Wed Oct 15, 2014 12:36 pm
by intl_sp
thanks! that helped...