Link to home
Start Free TrialLog in
Avatar of peterevison
peterevison

asked on

CFDirectory/CFFile

I need to query a database to get the originating path and move ALL files with in that originating path to the destination path(also in the database).  Can someone help me out.  

Here is what I have but it only moves the files from the first hit in the database query.  

<cfquery name="filemove" datasource="server">
select * from filemove
</cfquery>

<cfloop query="filemove">

<cfdirectory action="LIST" directory="#origin#" name="directoryList">

<cfloop query="directorylist">
<cffile action="move"
   source="#filecopy.origin##directorylist.name#"
   destination="#filemove.destin#">
   
   </cfloop>
   </cfloop>
Avatar of CFDevHead
CFDevHead

tRY THIS.
<cfquery name="filemove" datasource="server">
select * from filemove
</cfquery>

<cfloop query="filemove">
      <cfdirectory action="LIST" directory="#origin#" name="directoryList">
      <cfloop query="directorylist">
            <cffile action="move"
            source="#filecopy.origin##directorylist.name#"
            destination="#destin#">
      </cfloop>
</cfloop>
In you cffile tag
you had

 destination="#filemove.destin#">
which is always going to give you the first record in the query.

That is why you need to change it to this
 destination="#filemove.destin#">
Avatar of peterevison

ASKER

Now I'm getting error "Variable DESTIN is undefined."
Sorry about that
Try this
<cfquery name="filemove" datasource="server">
select * from filemove
</cfquery>

<cfloop query="filemove">
     <cfdirectory action="LIST" directory="#origin#" name="directoryList">
     <cfset destin_tmp=destin>
     <cfloop query="directorylist">
          <cffile action="move"
          source="#filecopy.origin##directorylist.name#"
          destination="#destin_tmp#">
     </cfloop>
</cfloop>
I somewhat works...Execpt when it gets to the second originating directory it looking for the same file name(s) from the first originating directory.  And of course that file is not there so it fails.

Its created a constant loop.
ASKER CERTIFIED SOLUTION
Avatar of CFDevHead
CFDevHead

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
COOL!

I was able to get it working....Thank you very much for you help.

The finishing touch I also had to add:

<cfset origin_tmp=origin>

So it looks like this:
<cfquery name="filemove" datasource="server">
select * from filemove
</cfquery>

<cfloop query="filemove">
     <cfdirectory action="LIST" directory="#origin#" name="directoryList">
     <cfset destin_tmp=destin>
       <cfset origin_tmp=origin>
     <cfloop query="directorylist">
          <cffile action="move"
          source="#origin_tmp##name#"
          destination="#destin_tmp#">
     </cfloop>
</cfloop>

CFDevHead,

You should also add a comment to my other posting.

https://www.experts-exchange.com/questions/21718803/List-with-cfdirectory-and-move-with-cffile.html

Its the same question but I never got an answer.  So I would like to give you the points for both.