Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.
-
ngeorgieff
- Posts: 4
- Joined: Thu Apr 19, 2012 5:44 pm
- Location: Los Angeles
Hi,
Is it possible to add a sequential number as suffix to file name.
For example: Read the last file name number and add one:
File.00001.txt +1
File.00002.txt +1
File.00003.txt +1
Thanks
Nikolay
-
Support_Duane
Support Specialist
- Posts: 66
- Joined: Thu Mar 05, 2009 3:49 pm
Yes, it is possible.
Here's an example. You'll need to change the name of the folder in which the files reside and both substring functions are based on a filename layout of xxxx.nnnnn.txt. If you're using something different, you'll need to change the parameters in the substring functions accordingly.
Code: Select all<project name="get last filename in filelist" mainModule="Main" version="2.0">
<module name="Main" logLevel="debug">
<createFileList fileListVariable="fl" numFilesFoundVariable="fc" version="1.0">
<fileset dir="/djohnson/addseq" />
</createFileList>
<forEachLoop itemsVariable="${fl}" currentItemVariable="thisFile" currentIndexVariable="i" beginIndex="${fc}">
<print version="1.0">
<![CDATA[i = ${i}]]>
</print>
<setVariable label="set count" name="count" value="${i + 1}" version="2.0" />
<setVariable label="set prefix = '.0000'" name="prefix" value=".0000" version="2.0" />
<if condition="${count >= 10}">
<setVariable label="set prefix = '.000'" name="prefix" value=".000" version="2.0" />
</if>
<if condition="${count >= 100}">
<setVariable label="set prefix = '.00'" name="prefix" value=".00" version="2.0" />
</if>
<if condition="${count >= 1000}">
<setVariable label="set prefix = '.0'" name="prefix" value=".0" version="2.0" />
</if>
<if condition="${count >= 10000}">
<setVariable label="set prefix = '.'" name="prefix" value="." version="2.0" />
</if>
<setVariable label="set newName" name="newName" value="${Substring(thisFile:name, 1, 4)}${prefix}${count}.txt" version="2.0" />
<print version="1.0">
<![CDATA[
new file name = ${thisfile:parentfile}/${newname}
]]>
</print>
<copy sourceFile="${thisfile}" destFile="${thisfile:parentfile}/${newname}" version="1.0" disabled="false" />
</forEachLoop>
</module>
</project>
-
ngeorgieff
- Posts: 4
- Joined: Thu Apr 19, 2012 5:44 pm
- Location: Los Angeles
Thank you. In this case we are using fileset count +1. If we delete some files, this will broke the sequential number.
-rw-r--r-- 1 root root 4835 May 24 16:54 File.00002.txt
-rw-r--r-- 1 root root 4835 May 24 16:54 File.00003.txt
-rw-r--r-- 1 root root 4835 May 24 16:55 File.00005.txt
-rw-r--r-- 1 root root 4835 May 24 17:17 File.00006.txt
------
-rw-r--r-- 1 root root 4835 May 24 16:54 File.00002.txt
-rw-r--r-- 1 root root 4835 May 24 16:54 File.00003.txt
-rw-r--r-- 1 root root 4835 May 24 17:21 File.00005 2.txt <------
-rw-r--r-- 1 root root 4835 May 24 16:55 File.00005.txt
-rw-r--r-- 1 root root 4835 May 24 17:17 File.00006.txt
-
monahanks
- Posts: 41
- Joined: Wed Mar 30, 2011 10:19 am
You can connect to a SQL database that stores the sequential number, retrieve the number and then update the sequence with a +1. Our method involves stored procedures and a table of different sequence numbers keyed by a file type (AA is an order file, BB is sales, etc). It gets a little involved (to me) since I'm new to SQl and stored procedures, but it works well. The project that handles the SQL database access and retrieval is in a common folder accessible (or included in) any project that needs a sequential number.