2019-07-05 22:21:47

Hi all,
I was wondering if anyone knew of a way of copying a directory to another one in bgt, including all of it's subfolders / files?
The only ways I've thought to do this so far haven't really worked well at all. The closest thing I've been able to do so far was write a function that takes an array containing all the folders to copy then another containing all of the files, but of corse that just puts all the files and folders in the location you spessify regardless of where they should be, which is quite messy.
Thanks in advance.

2019-07-05 22:28:56

BGT has functions for find files and find directories, but it doesn't have a way to directly copy a directory. You can copy files though.
This is actually super easy to accomplish in Python with a couple lines of code, but I'm not sure the less complex way of handling this in BGT.

My name is Inigo Montoya. You killed my space bar. Prepare to die!

http://l-works.net

2019-07-05 23:10:58

Do you want it to be recursive, and can you proof it against people copying a directory into itself and causing it to replicate until you run out of disc space?
You can probably get away with directory_create, then use a for loop to copy the files. Unless file_copy takes wildcards, in which case file_copy(dir + "\\*", newdir + "\\*")... but I think you need the loop.
To make it recursive, you'd need a function that calls itself for every subdirectory. Again, with something like that, it must be able to avoid copying to itself, otherwise it will not stop until you run out of space, and maybe not even then, if it just ignores errors and keeps trying.

Ex:
void deepcopy (string head, string dest) {
    string[] dirs = find_directories(head + "\\*");
    for (uint j = 0; j < dirs.length(); j++) deepcopy(head + "\\" + dirs[j], dest + "\\" + dirs[j]);
    string[] files = find_files(head + "\\*");
    for (uint j = 0; j<files.length(); j++) file_copy(head + "\\" + files[j], dest + "\\" + files[j]);
}
Disclaimer: not tested, not infinite-proof.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

2019-07-05 23:37:10

Yeah, it should be recursive. Your function might just work, I'll just need to figure out a way I can make it work properly how I want to. Thanks anyways.