Page 1 of 1

retrieve file information?

Posted: Tue Jun 21, 2011 10:37 am
by monahanks
Hi, can GoAnywhere be used to retrieve information about a file on a Windows server, such as the last time a file was updated? We have a case where a file sits on a Windows server and always has data in it, but if today's update did not run, the data would be from yesterday. Can I use GA to retrieve the last update time of the file and match that against the current date to see if I want to process the data? This would be similar to the DSPFD command on the AS400, or the DIR command on a windows system to see the date of a file.

Re: retrieve file information?

Posted: Tue Jun 21, 2011 1:05 pm
by Support_Julie
The file attribute lastModifiedDate will give you the desired result.

To retrieve the attributes of a complex variable use the following variable reference syntax.


The colon (:) separates the variable from the attribute.

Re: retrieve file information?

Posted: Tue Jun 21, 2011 1:40 pm
by monahanks
Hi Julie, I'm not sure where I would use this variable reference syntax you mention, and I'm not finding anything in the Webhelp. Can you point me in the right direction or show me a code snippet of how it is used?

Re: retrieve file information?

Posted: Tue Jun 21, 2011 4:16 pm
by Support_Julie
Below I have attached a small sample project that retreives a file list & then prints out the file attributes.
If you so desired, you could Set a Variable to check a condition later.

<project name="Print FileList attribute variables" mainModule="Main" version="1.0">

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

<createFileList fileListVariable="fileList" numFilesFoundVariable="fileCount" version="1.0">
<fileset dir="/temp/mltmbr" />

<forEachLoop itemsVariable="${fileList}" currentItemVariable="thisFile">

<setVariable label="fill trimFileName" name="trimFileName" value="${thisFile:path}" version="1.0" />

<setVariable label="fill mbrName" name="mbrName" value="${thisFile:nameWithoutExtension}" version="1.0" />

<print version="1.0">
<![CDATA[Attribute List
name: ${thisFile:name}
extension: ${thisFile:extension}
last modified date:${thisFile:lastModifiedDate}
size: ${thisFile:size}
path: ${thisFile:path}
nameWithoutExtension: ${thisFile:nameWithoutExtension}
parentFile: ${thisFile:parentFile}


<variable name="libName" value="mylib" />

Re: retrieve file information?

Posted: Wed Jun 22, 2011 6:42 am
by monahanks
Thanks Julie. Now, one more question: can I substring (or extract) just the date portion of the lastModifiedDate and compare it to the system current date?

Re: retrieve file information?

Posted: Mon Jun 27, 2011 11:18 am
by Support_Duane
Use the print statement to write the last changed date out to a file, then read it in as a delimited file using a space as the delimiter. You then have to do a set variable version 1.0 task to get the date out of the rowset. It will be in yyyy-MM-dd format. If you don’t want the dashes, you can do a search and replace on the file before you do the read CSV.

Here are the XML lines without a search and replace
Code: Select all
	<print label="write date to file" file="date.csv" append="false" version="1.0">
	<readCSV inputFile="date.csv" outputRowSetVariable="data" fieldDelimiter="space" skipFirstRow="false" recordDelimiter="LF" textQualifier="none" version="1.0" />
	<setVariable name="date" value="${data[1]}" version="1.0" />