Skip to main content
hopibuddha12
Participant
August 28, 2009
Question

<CFFile> move files From folder A to Folder B

  • August 28, 2009
  • 4 replies
  • 1517 views

Rather new to this and forgive me if it's a stupid question.  Is there a way in CF to move files from Folder A to Folder B at a certain time during the day? I don't know if I need to fumble around with CFFILE tag or not, sort of hit a brick wall on this and don't know where to turn.

Thanks!

DA

    This topic has been closed for replies.

    4 replies

    hopibuddha12
    Participant
    September 2, 2009

    The basic code that was provided helped as a guide. I am working with it further to tailor it to my own system.

    Inspiring
    August 31, 2009

    If you have control over the server in question, a windows batch file or unix shell script would be a lot simpler than using cold fusion.

    hopibuddha12
    Participant
    August 31, 2009

    Dan:

    It's a strange situation here, I've never worked in a web shop before that didn't have admin permissions on the web server much less the SQL server.  Like you, I immediately thought of writing a batch file, but the way the network folks have the boxes locked down, I would never get it done with the permission set I have currently.

    Darrell

    Inspiring
    August 30, 2009

    Hi There,

    This would be accomplished in a two step process.

    You should be able to copy and paste code below into a .cfm

    page and then replace the  the square brackets [ ] and content

    within with the information for your system and you should be

    good to go.

    Then to run this on a specified date, time etc., you setup a

    scheduled task in the CF Administrator or use the <cfschedule>

    to launch the process at the desired intervals.

    Hope this helps you out.

    Leonard

    =====================

    Copy everything below here

    <!--- Step 1:
    Use the <cfdirectory tag to retrieve a listing for files within a given
    folder/directory. This information will be stored in a query record
    which can later be used in your <cffile> tag for moving files.
    --->

    <cfdirectory
    directory="[Drive Letter]:\[path_to]\folder_a\"
    action="list" <!--- List files in directory in a query record --->
    name="dirFiles" <!--- Same as a query name --->
    <!--- filter="*.pdf" Only affects files with .pdf extension (remove for all files) --->
    recurse="no"
    type="File"> <!--- List only the filename --->

    <!--- Use the code below on the same page as the <cfdirectory> to see the
    contents of the desired folder --->

    <cfoutput query="dirFiles">
    <p>#name#</p>
    </cfoutput>

    <!--- Step 2:
    Then to move the files to folder b, insert the following code on the page.
    Using the <cfloop> tag with a query attribute, will loop through the
    results from the <cfdirectory> process and move each file to folder b.
    --->

    <cfloop query="dirFiles">
    <cffile
    action="move"
    destination="[Drive Letter]:\[path_to]\folder_b\"
    source="[Drive Letter]:\[path_to]\folder_a\#name#">
    </cfloop>

    hopibuddha12
    Participant
    August 31, 2009

    LeonardB:

    Thanks a bunch!  You've given me a great place to start.  I will work with this today and see how I can tweak/add to the code you've provided.  I'll report back here later with results.

    Thanks!

    DAnderson

    Inspiring
    August 28, 2009

    cffile can move files.  If you tried and were unsuccessful, post the code and results.

    On your admin page, you can set up scheduled jobs.