retrieve file information?
Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.
retrieve file information?
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.
- Support_Julie Offline
- Support Specialist
- Posts: 91
- Joined: Thu Mar 05, 2009 3:49 pm
- Location: Ashland, NE USA
- Contact:
Re: retrieve file information?
The file attribute lastModifiedDate will give you the desired result.
To retrieve the attributes of a complex variable use the following variable reference syntax.
${variableName:attributeName}
The colon (:) separates the variable from the attribute.
To retrieve the attributes of a complex variable use the following variable reference syntax.
${variableName:attributeName}
The colon (:) separates the variable from the attribute.
Re: retrieve file information?
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?
- Support_Julie Offline
- Support Specialist
- Posts: 91
- Joined: Thu Mar 05, 2009 3:49 pm
- Location: Ashland, NE USA
- Contact:
Re: retrieve file information?
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" />
</createFileList>
<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}
]]>
</print>
</forEachLoop>
</module>
<variable name="libName" value="mylib" />
</project>
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" />
</createFileList>
<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}
]]>
</print>
</forEachLoop>
</module>
<variable name="libName" value="mylib" />
</project>
Re: retrieve file information?
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?
- Support_Duane Offline
- Support Specialist
- Posts: 66
- Joined: Thu Mar 05, 2009 3:49 pm
Re: retrieve file information?
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
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">
<![CDATA[${thisFile:lastModifiedDate}]]>
</print>
<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" />