Page 1 of 1

Rename file by file size

Posted: Thu Jan 02, 2014 10:14 am
by Jlipp
I have a two files that we pull from a system that are typically named with just numbers. I want to drop these two files int a monitored folder and when both are in there to rename and send them.

There is no consistency in the numbers that come out of our system so I really can't base the file name change on the incoming file name. I need to change the file names based on file size. One is always under 200 KB and the other is always over 1 MB.

I've looked through a lot of the documentation and haven't found anything in regards to making fie name changes based only on file size. Has anyone done this or know if this is an option?

Re: Rename file by file size

Posted: Thu Jan 02, 2014 10:28 am
by Support_Rick
JLipp,

When you have a filelist variable (created from a Monitor or CreateFileList task, etc) you have access to the File Attributes. By putting the FileList variable into a ForEach loop, you can test for file size with something like this:
Code: Select all
<forEachLoop label="Loop through list of Docs" itemsVariable="${lsFiles}" currentItemVariable="file">

			<setVariable label="Set File Name" name="stat_filename" value="${ file:name }" version="2.0" />
			<setVariable label="Set File Size" name="stat_filesize" value="${ file:size }" version="2.0" />

Or, utilize the "FileInfo" function if you already have the file path/name inside a variable:
Code: Select all
<project>
	<variable name="FileName1" value="\Temp\1.jpg" />
	<variable name="FileName2" value="\Temp\2.jpg" />
  <module="main">
...
		<if label="Compare File Size" condition="${ ( FileInfo( String( FileName1 ) ):size ) == ( FileInfo( String( FileName2 ) ):size ) }">

  </module>
</project>

Re: Rename file by file size

Posted: Fri Jan 03, 2014 12:30 pm
by Jlipp
I ended up using a couple of if statements and some other workarounds, but ended up getting it work. Thanks for the help!