How do I Delete A Folder Using Node-Webkit?

0 favourites
  • 6 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • 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.

  • 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. ... in-nodejs/ ... 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.

  • 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.

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)