File Move to Sub Directory

Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.

File Move to Sub Directory

Postby smandadi » Mon Sep 13, 2010 6:15 pm

How do I move the File to sub directories based on File name meta data.
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: 17
Joined: Mon Jun 14, 2010 3:58 pm

Re: File Move to Sub Directory

Postby Support_Erick » Thu Sep 16, 2010 8:18 am

Can it be assumed that the folder ABCD already exists, or must it be created dynamically? If there are a finite set of file prefixes, and the folders can be created beforehand, it is much simpler.

Please let us know and we can post a sample project.
Support_Erick
Support Specialist
 
Posts: 12
Joined: Thu Mar 05, 2009 10:20 am

Re: File Move to Sub Directory

Postby smandadi » Thu Sep 16, 2010 11:27 am

NO... Missed that point earlier... ABCD is a variable value. and a Folder needs to be created...

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: 17
Joined: Mon Jun 14, 2010 3:58 pm

Re: File Move to Sub Directory

Postby smandadi » Thu Sep 16, 2010 2:39 pm

For already existing folders,, I was able to run this Sample Project....
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: 17
Joined: Mon Jun 14, 2010 3:58 pm

Re: File Move to Sub Directory

Postby Support_Erick » Mon Sep 27, 2010 2:38 pm

There is no direct way this can be accomplished in GoAnywhere Director, however, we have a workaround that will work (See below). We have opened a case to add functionality to make this easier to accomplish in a future release.

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: 12
Joined: Thu Mar 05, 2009 10:20 am


Return to Community Forum

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron