April 7th, 2013, 05:05 AM
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 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
<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#)>
<cfdirectory action="list" directory="#directory#" name="directories" recurse="true" type="dir" />
<cfdirectory action="delete" directory="#directory#/#directories.name#" recurse="yes">
<cfloop from="1" to="#folders_to_create#" index="i">
<cfif folders_to_create EQ 1>
#folders_to_create# folder created
#folders_to_create# folders created
April 7th, 2013, 11:05 AM
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?
April 7th, 2013, 03:18 PM
@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
April 8th, 2013, 09:25 AM
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?
April 8th, 2013, 11:58 AM
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.
April 8th, 2013, 12:12 PM