4 Replies - 1401 Views - Last Post: 08 April 2013 - 05:14 AM Rate Topic: -----

#1 anarchos78  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-April 13

Copy files in folders using ColdFusion (openBD Engine)

Posted 07 April 2013 - 03:23 AM

I have been asked to solve the following problem: copy files in batch of 3 in newly created folders. Example: in folder letís say ďD:/TEST_CF/Ē there are 20 txt files. Divide them by 3 (the batch-give us 6 remainder 2), create 7 folders (in order to place the batches of 3 in the 6 folders and the remaining 2 files in the 7th folder). What I have done until now is to create the needed folders. But, I canít copy the files into batches of 3 in the newly created folders. How should I tackle the above problem?

Any help would be greatly appreciated.

The code block

<html>
<body>

<cfprocessingdirective pageencoding="UTF-8">

<cfset directory = "D:/TEST_CF/">
<cfdirectory directory="#directory#" name="files" action="list" type="file">
<cfset filecount = #files.RecordCount#>
<cfset divisor = 3>
<cfset division = #filecount# / #divisor#>
<cfset remainder = #filecount# MOD #divisor#>
<cfset folders_to_create = Ceiling(#division#)>

<cfoutput>

    <cfif directoryExists(directory)>        
        <cfdirectory action="list" directory="#directory#" name="directories" recurse="true" type="dir" />
        <cfloop query="directories">
            <cfdirectory action="delete" directory="#directory#/#directories.name#" recurse="yes">
        </cfloop>
    </cfif>    

    <cfloop from="1" to="#folders_to_create#" index="i">
        <cfdirectory
          action="create"
          directory="#directory#newfolder#i#">
    </cfloop>

    <cfif folders_to_create EQ 1>
        #folders_to_create#&nbsp;folder created
    <cfelse>
        #folders_to_create#&nbsp;folders created
    </cfif>
</cfoutput>

</body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: Copy files in folders using ColdFusion (openBD Engine)

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: Copy files in folders using ColdFusion (openBD Engine)

Posted 07 April 2013 - 11:14 AM

Quote

But, I canít copy the files into batches of 3 in the newly created folders.

Why not? What have you tried so far? What errors did that produce?
Was This Post Helpful? 0
  • +
  • -

#3 anarchos78  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-April 13

Re: Copy files in folders using ColdFusion (openBD Engine)

Posted 07 April 2013 - 01:15 PM

@tlhIn`toq The part that causing me problem is copy. I have changed the the above process using cfc. After folders creation all the files (20) are copied in the first folder. For the cfm follow The cfm and for the cfc follow The cfc
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: Copy files in folders using ColdFusion (openBD Engine)

Posted 07 April 2013 - 02:23 PM

View Postanarchos78, on 07 April 2013 - 02:15 PM, said:

After folders creation all the files (20) are copied in the first folder.


We must be experiencing a language barrier problem. What is the problem? If all the files are copied into the folder that sounds like it works.
Was This Post Helpful? 0
  • +
  • -

#5 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: Copy files in folders using ColdFusion (openBD Engine)

Posted 08 April 2013 - 05:14 AM

Welcome to DIC, anarchos78. I've had a look at your question and code and I think I've got a grip on what you're wanting to do.

I see that you're familiar with the CFDIRECTORY tag in that your code can take a listing of a directory's contents and you have another block of code that creates and deletes directories. For what you're wanting to do, that's actually the more challenging part.

What you'll need to do now (maybe inside the loop starting at line 23) is to discover the CFFILE tag and the action attribute, "copy". Give that link a read and I believe that will guide you to what you want to do. If you run into any issues with that effort, drop back by and we'll see what we can do.

Good luck!

This post has been edited by Craig328: 08 April 2013 - 05:15 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1