File Move to Sub Directory
File Move to Sub Directory
My File would be in the format /usr/work/ABCD-xyz-123.txt
That needs to be Moved to /usr/work/ABCD/ABCD-xyz-123.txt
FTP Server is GoAnywhere Services.. (In case, I can do this directly using Triggers please suggest)
Here is a Sample Project... That I envision. (Please suggest any other way that this can be achieved).
- Code: Select all
<project name="MovetoSub" mainModule="Main" version="1.0">
<module name="Main">
<ftp version="1.0" resourceId="FTP Server">
<list label="FilestoMove" fileListVariable="FilestoMove">
<fileset dir="/usr/work" recursive="false">
<wildcardFilter>
<include pattern="*IncludePattern*" />
</wildcardFilter>
</fileset>
</list>
</ftp>
<forEachLoop itemsVariable="${FilestoMove}" currentItemVariable="currFile">
<setVariable version="2.0" label="DirName" value="????" />
<ftp version="1.0" resourceId="FTP Server">
<mkdir dir="/usr/work/${DirName}" />
<move sourceFile="${currFile}" destinationFile="/usr/work/${DirName}/${currFile:file} />
</ftp>
</forEachLoop>
</module>
</project>
- smandadi
- Posts: 14
- Joined: Mon Jun 14, 2010 2:58 pm
Re: File Move to Sub Directory
Please let us know and we can post a sample project.
- Support_Erick
- Support Specialist
- Posts: 8
- Joined: Thu Mar 05, 2009 9:20 am
Re: File Move to Sub Directory
To be specific, The Part before the First Hyphen needs to be used as a Folder... and the File be moved under the newly created Directory structure.
- smandadi
- Posts: 14
- Joined: Mon Jun 14, 2010 2:58 pm
Re: File Move to Sub Directory
The issue is when I had to create these Folders also......
- Code: Select all
<project name="RSS" mainModule="Main" version="1.0">
<module name="Main">
<ftp version="1.0" resourceId="FTP Server">
<rename searchPattern="(.*?)-(.*)" patternType="regex" replaceWith="$1/$1-$2">
<fileset dir="/usr/work" recursive="false" />
</rename>
</ftp>
</module>
</project>
- smandadi
- Posts: 14
- Joined: Mon Jun 14, 2010 2:58 pm
Re: File Move to Sub Directory
- Code: Select all
<project name="Rename File to Sub Directory" mainModule="Main" version="1.0" logLevel="normal">
<module name="Main">
<createWorkspace version="1.0" />
<ftp resourceId="GoAnywhere Services FTP Server" version="1.0">
<list label="Get List of Files to Move" fileListVariable="ftpFiles" numFilesFoundVariable="numFiles">
<fileset dir="/inbound/">
<wildcardFilter>
<include pattern="*-*-*" />
</wildcardFilter>
</fileset>
</list>
</ftp>
<print file="filename.csv" version="1.0" />
<forEachLoop itemsVariable="${ftpFiles}" currentItemVariable="file" logLevel="silent">
<print label="Write File Names to CSV in Workspace" file="filename.csv" append="true" version="1.0">
<![CDATA[${file:name}${system.lineFeed}]]>
</print>
</forEachLoop>
<searchAndReplace label="Replace dash with tilde" inputFile="filename.csv" outputFile="filename2.csv" searchFor="-" replaceWith="~" version="1.0" />
<readCSV label="Parse File Names into Chunks" inputFile="filename2.csv" outputRowSetVariable="nameParts" fieldDelimiter="tilde" recordDelimiter="LF" skipInvalidRecords="true" version="1.0" />
<forEachLoop itemsVariable="${nameParts}" currentItemVariable="namePart" logLevel="silent">
<ftp label="Connect and Move Each File" resourceId="GoAnywhere Services FTP Server" version="1.0" logLevel="normal" executeOnlyIf="${numFiles} gt 0">
<cd label="CD to Appropriate Folder" dir="/inbound" />
<move label="MOVE each File" sourceFile="${namePart[1]}-${namePart[2]}-${namePart[3]}" destinationFile="${namePart[1]}/${namePart[1]}-${namePart[2]}-${namePart[3]}" />
</ftp>
</forEachLoop>
<deleteWorkspace version="1.0" disabled="false" />
</module>
</project>
- Support_Erick
- Support Specialist
- Posts: 8
- Joined: Thu Mar 05, 2009 9:20 am
Who is online
Users browsing this forum: No registered users and 1 guest