EasyCFM.COM ColdFusion Forums / Coding Help! / Copy files in folders using ColdFusion (openBD Eng

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Copy files in folders using ColdFusion (openBD Eng

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

anarchos78
04-07-2013 @ 3:20 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Member
Posts:
Joined: May 2012

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>

cfSearchin
04-22-2013 @ 12:50 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 608
Joined: Feb 2008

http://stackoverflow.com/a/15871496/104223


Website Designed and Developed by Pablo Varando.