Page 1 of 1

adding date stamp

Posted: Wed Oct 05, 2016 12:49 pm
by ehersh
I am going into a folder and pick up multiple files using a wild card. For example the wild card says test*.*. That will pick up test1.txt, test2.txt etc. However when I deposit them into another folder I need to put a date stamp on so file names are test1_yyyymmdd.txt, test2_yyyymmdd.txt etc. I can generate the date stamp I am having the problem is I can prefix the entire file with the date-time stamp or suffix it. Is there a way to insert the date stamp prior to the .txt? So instead of test1.txt_yyyymmdd I would have test1_yyyymmdd.txt.

Re: adding date stamp

Posted: Fri Oct 07, 2016 3:42 am
by Support_Rick
When you pick up the multiple files using a wild card, you're creating what's called a "FileList Variable".

Using this FileList variable, you can loop through the files individually and process them 1 for 1, or you can process them as a whole using the FileList Variable.

in this case, you'd need to process them individually, allowing you to rename them as you go. This allows you to take full advantage of the File Attributes associated to the FileList variable.

Is Pseudo terms, you would do something like:

CreatefileList MyFileList
ForEach MyfileList -> ThisFile
Copy File ${ThisFile} to ${ concat( ThisFile:nameWithoutExtension, '_', currentDate('yyyyMMdd'), '_', ThisFile:extension ) }
EndForEach

Re: adding date stamp

Posted: Fri Oct 07, 2016 7:22 am
by ehersh
Thank you

Re: adding date stamp

Posted: Mon Oct 17, 2016 11:52 am
by ehersh
I have tried that numerous times, I am getting the following error:
Project 'Project Name' failed. Job number is '1397289360302'.
[8099 - copy to archive] An unexpected error occurred. Function 'Concat': Parameter '1' must be a string value. Function definition: 'Concat(text, text[, text...]) returns string' Original expression: concat(current_file, '_',currentDate('yyyyMMdd'),'.txt').


This is my copy statement where my destination is resource:smb://directory/home/EDI\Goanywhere_testing/Inbound/${concat(current_file, '_',currentDate('yyyyMMdd'),'.txt')}

current file is the variable for the current file in the for each loop

Re: adding date stamp

Posted: Mon Oct 17, 2016 1:19 pm
by Support_Rick
Replace your Var:

${concat(current_file, '_',currentDate('yyyyMMdd'),'.txt')}

With this:

${concat( string(current_file), '_',currentDate('yyyyMMdd'),'.txt')}

Re: adding date stamp

Posted: Mon Oct 17, 2016 4:33 pm
by ehersh
now it is telling me resource:smb://resource/dir/Goanywhere_testing/Inbound/wrongfile1.txt_20161017' not found but that directory does exist I have trried numerous modifications all to no avail.

Re: adding date stamp

Posted: Mon Oct 17, 2016 5:07 pm
by Support_Rick
Are you sure it's not supposed to be:

resource:smb://resource/dir/Goanywhere_testing/Inbound/wrongfile1_20161017.txt

instead of:

resource:smb://resource/dir/Goanywhere_testing/Inbound/wrongfile1.txt_20161017

If that's the case, look into your file attributes (you can search for those in the help). Then, review the attribute "nameWithoutExtension".

Then try something like:

${ concat( string( current_file:nameWithoutExtension ), '_', currentDate('yyyyMMdd'), '.txt' ) }

Re: adding date stamp

Posted: Tue Oct 18, 2016 8:11 am
by ehersh
I did get through that OK now it appears it can't find the attribute nameWithoutExtension

ERROR [8099 - renamed file] An unexpected error occurred.
Method 'getNameWithoutExtension' or 'isNameWithoutExtension' not found on class 'com.linoma.dpa.util.FileList'.
Original expression: concat(string(get_file:nameWithoutExtension),'_',currentDate('yyyyMMdd'),'.txt').

Below is how I coded it.

${concat(string(get_file:nameWithoutExtension),'_',currentDate('yyyyMMdd'),'.txt')}

get_file is the file list variable

Re: adding date stamp

Posted: Tue Oct 18, 2016 10:11 am
by ehersh
this is the xml
Code: Select all
<project name="tstdatefilenameesh" mainModule="Main" version="2.0" logLevel="verbose">
	<description>test claim file movements</description>

	<module name="Main">

		<createWorkspace version="1.0" />


		<timestamp label="timestamp" version="1.0">
			<format outputVariable="year" pattern="yyyy" />
			<format outputVariable="month" pattern="MM" />
			<format outputVariable="day" pattern="dd" />
		</timestamp>


		<createFileList label="get file" fileListVariable="get_file" numFilesFoundVariable="count_files" version="1.0" disabled="false">
			<fileset dir="<path to>/Goanywhere_testing/Inbound/">
				<wildcardFilter>
					<include pattern="wrong*.*" />
				</wildcardFilter>
			</fileset>
		</createFileList>

		<forEachLoop label="loop" itemsVariable="${get_file}" currentItemVariable="current_file" currentIterationVariable="current_file" disabled="false" />

		<setVariable label="renamed file" name="renamed_file" value="${concat(string(get_file:nameWithoutExtension),&apos;_&apos;,currentDate(&apos;yyyyMMdd&apos;),&apos;.txt&apos;)}" version="2.0" disabled="false" />


		<copy label="copy to archive" sourceFilesVariable="${current_file}" destDir="<path to>\Goanywhere_testing/Inbound/test" whenFileExists="rename" processedSourceFilesVariable="current_file" destinationFilesVariable="${renamed_file}" version="1.0" logLevel="debug" disabled="false" />

	</module>

</project>

Re: adding date stamp

Posted: Wed Oct 26, 2016 7:51 am
by ehersh
This has been resolved. I did not have my copy within the for each loop and needed to add a workspace.