How do I increment a number at the end of a filename?

Looking for an example project to get you started?
1 post Page 1 of 1

Support_Duane

Support Specialist
Posts: 66
Joined: Thu Mar 05, 2009 3:49 pm

Post by Support_Duane » Wed Mar 25, 2009 4:51 pm
Here is an example project for an iSeries. It can be modified to run using almost any other database server.
Code: Select all
<project name="TEST SQL using QTEMP" mainModule="Main" version="1.0">

	<module name="Main" logLevel="debug">

		<timestamp>
			<format outputVariable="cymd" pattern="yyyyMMdd" />
		</timestamp>

		<createFileList label="Count Files" numFilesFoundVariable="filesFound">
			<fileset dir="/djohnson/outfile">
				<wildcardFilter>
					<include pattern="prefix_${cymd}_*" />
				</wildcardFilter>
			</fileset>
		</createFileList>

		<sql label="SQL" resourceId="Dev61">
			<query label="create table">
				<statement>create table qtemp.filecount (files NUM(3))</statement>
			</query>
			<query label="insert count value" whenNoDataFound="continue">
				<statement>INSERT INTO qtemp.filecount(files) values(${filesFound} + 1)</statement>
			</query>
			<query label="Get File_Count" outputVariable="File_Count">
				<statement>SELECT  case                                      
                               When files < 10     then &apos;00&apos; 
                               When files < 100    then &apos;0&apos;  
                               end
                       concat trim(char(files)) from qtemp.filecount</statement>
			</query>
		</sql>

		<setVariable name="FileCount" value="${File_Count[1]}" />

		<setVariable label="initialize file name" name="fileName" value="prefix_${cymd}_${FileCount}.zip" />

		<copy label="Copy File" sourceFile="/source_path/filename" 
destFile="/destination_path/${fileName}" whenFileExists="overwrite" />

	</module>

</project>
To give it a try to see how it works, change the name of the source_path and filename and the destination path and change the prefix if desired.
1 post Page 1 of 1