I am building a program that manages the quantity and distribution of files and folders from folder "a" to "b" in java (io , nio, apache commons-io) libs.
I got stuck at a point where i can move files from "a" to "b" but not subfolders(directories) of "a" or vice versa where i can move subfolders but not files, and at one time it got me laughing because it moved the files and the files that are contained in the sub folders of "a", but not the folders.
the thing is i don't want to copy the whole "a" to "b" in a 1-to-1 copy, i am building a management tool that puts every "x" items(either files or folders) in a sub-"b"-folder.
I could manage that part of management and segmenting. But what i am stuck at specifically the pointer if called correctly, i could not get it to point at folders and files at "a" one folder/file at a time to be handled by the program.
sincerely sorry if my explanation was not clear.
Edit: the last thing that I could come up with, is to parse it into an array but did not work out. for the main it only has strings that point to the location and if path exists arguments, a call for the copy method.
Edit #2: noticed that i didn't mention that in main there would be an integer that would co-relate to both of init and limit; it's purpose is to limit the copying per subfolder towards "b".
reference code :
public static boolean copyRecurse(String source, String destination, int limit,int init){
if (limit <= 0){System.out.println("Exiting..."); return true;}
if (limit == init){System.out.print("copying");}
System.out.println(".");
//copies the whole directory as is
/*
try {
copyDirectory(new File(source), new File(destination));
}catch (IOException e) {e.printStackTrace();}
*/
// failed attempt to make it copy by one subfolder/file at a time
try {
copyFile(new File(String.valueOf(Arrays.stream(Objects.requireNonNull(new File(source).listFiles())).findFirst())), new File(destination));
}catch (IOException e) {e.printStackTrace();}
copyRecurse(source,destination,limit-1,init);
return true;
}
Apparently, there is a parsing into an array in commons IO method called "File[]"
Note: that it's in a recursion function or a double loop to increment the "increasingInteger" and "index" so you could build a folder limiting structure i.e. ("increasingInteger" = part)
Destination folder
| part1
|| number of items (folders and files) inside part1
| part2
|| number of items (folders and files) inside part2
| part3
|| number of items (folders and files) inside part3
for my case (selecting either a file or a folder) this is what I came up with: