#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    8
    Rep Power
    0

    Copy files in folders using ColdFusion (openBD Engine)


    I have been asked to solve the following problem: copy files in batch of 3 in newly created folders. Example: in folder lets 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 cant 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
    Code:
    <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>
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    I'm not really sure what you're asking, since you don't have any code that actually copies the files. Are you getting an error or something?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    8
    Rep Power
    0
    @kiteless 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
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    You're using this arrayGroupsOf() method to create a group of arrays, but you're not using that group of arrays to actually loop and move the files.

    Does the result of arrayGroupsOf() contain the groups of directories and files that you want to use in your file move operations?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    8
    Rep Power
    0
    The result contains the desired groups but, I am not experienced enough to write down the loop needed. Is there any good book on array stuff? Many thanks for looking to my problem.
  10. #6
  11. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    You can start with the docs (http://openbd.org/manual/?/language_creation#array).

    More generally: http://en.wikipedia.org/wiki/Array_data_type

    Honestly, arrays are one of the most fundamental programming constructs there is. Virtually every language has some form of arrays. So if you don't understand how arrays work, you probably need to stop what you're doing and learn how they work.
    Last edited by kiteless; April 8th, 2013 at 12:15 PM.

IMN logo majestic logo threadwatch logo seochat tools logo