How do I Delete A Folder Using Node-Webkit?

Get help using Construct 2

Post » Sat Nov 29, 2014 10:10 pm

I may be missing something completely obvious.

In Node-Webkit's actions I see the "Delete File" action, but no "Delete Folder". The "Delete File" action accepts a path, and I tried a path to a folder to be deleted, but it does not seem to work. All the other file and folder actions behave as expected, so I don't think this is related to a file or folder's access permissions.

I've tried to check the manual entry on Node-Webkit but it seems to just lead to a download page for the plugin.

I'm using the latest version of C2 and the Node-Webkit plugin.
B
17
S
2
Posts: 66
Reputation: 1,382

Post » Sun Nov 30, 2014 1:14 am

Well, it doesn't look like that functionality is exposed in the Node-Webkit plugin, though it does exist. It could be Ashley choose not to expose it for security reasons (you don't want to make a mistake with that kind of command).

Removing empty directories is straightforward, it calls the following function from node's file system API: fs.rmdir(path, callback)

Removing dirs with files in them requires a couple extra steps.

http://www.geedew.com/2012/10/24/remove ... in-nodejs/

http://stackoverflow.com/questions/1262 ... irectories

tl;dr: you would have to modify the node-webkit plugin to accomplish this, or convince Ashley to expose that part of the API.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Sun Nov 30, 2014 2:53 am

Ah, well it's good to know that I'm not just missing something.

I'm a little surprised that I can delete files but not folders.

Anyway, thanks for looking into this for me TiAm.
B
17
S
2
Posts: 66
Reputation: 1,382

Post » Sun Nov 30, 2014 9:31 am

I modified the Node-Webkit plugin to allow for removing an empty directory.

I also attempted to include the recursive folder deletion, but I don't really know JS or programming much at all, so I failed at that.

My next thought was to simply expose the ability to check if a path is a directory or a file in C2, then I could implement the recursive folder deletion from within construct, a much more familiar environment. I've failed at this as well so far, however.

For now, I think that there is a very ugly method I can use to recursively delete a folder within construct using only the delete-an-empty-folder option.
B
17
S
2
Posts: 66
Reputation: 1,382

Post » Sun Nov 30, 2014 8:09 pm

Are you just trying to destroy folders containing files you have created with the runtime? If so, maybe it would be safer to explicitly delete those files, then delete the empty folder using the fs.rmdir command (which fails if the directory isn't empty).

This way if you make a mistake with the folder you're trying to delete, it won't do any harm.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Sun Nov 30, 2014 9:12 pm

I am indeed only trying to delete files in folders that I have created with the runtime.

What I'm trying to make is a profiles system. What a profile is, is just a folder with a name. In a "Profiles" folder.

With the runtime, I create an "insert-game-name-here" folder in the Appdata\Roaming Directory. Inside this I create the "Profiles" folder.
So far, I have profile creation working well enough, but I also want the user to be able to delete a profile. This should just mean deleting the folder and all of it's contents.

The reason that I don't want to/can't just delete all the files in the folder explicitly is that the # of files, and folders and further sub-folders in the particularly profile-folder that I want to delete will vary depending on the profile.
B
17
S
2
Posts: 66
Reputation: 1,382


Return to How do I....?

Who is online

Users browsing this forum: ChesVCF, LaDestitute, OBLIVION, Solomon and 24 guests