• File deleting & attributes

    From Nightfox@VERT/DIGDIST to All on Fri Sep 4 03:50:42 2009
    I'm working on a JavaScript script for Synchronet that involves extracting an archive into a temporary directory, and then it will recursively delete the temporary directory when it's done.
    My BBS is running in Windows 2000, and it looks like if one of the extracted files has the read-only attribute set, file_remove() doesn't remove it. I then started to look into how file attributes are represented in Synchronet's JavaScript model and if it's possible to change them. I noticed that the File class has a property called 'attributes', and there's also a function called file_attrib(), which will give you a file's attributes. The attributes are represented by a number, but the docs don't seem to say what that number means or if there are any variables anywhere that represent different file attributes. I checked sbbsdefs.js and didn't see any mention of file attribute definitions in there.

    So, my questions are:
    1. Is it possible to delete a file regardless of its attributes? And if so, how?
    2. For File's attribute property and file_attrib()'s return value, what are the attribute values that it can be checked against (or more precisely, where can I find the list of attributes)?
    3. If you wanted to change a file's attributes, can that be done by opening it with the File class, changing its attributes property, and saving the file?

    Eric

    ---
    þ Synchronet þ Digital Distortion BBS: digdist.bbsindex.com
  • From Nightfox@VERT/DIGDIST to All on Fri Sep 4 04:31:26 2009
    Re: File deleting & attributes
    By: All to Nightfox on Thu Sep 03 2009 20:50:42

    As a follow-up to my last message, if I want to recursively delete a temporary directory after extracting an archive into it, I thought of a simpler solution.
    If in Windows, I could have my script execute the "rd /s /q" command; otherwise assume *nix and use "rm -rf", as follows:

    function deltree(pDir)
    {
    if (/^WIN/.test(system.platform.toUpperCase()))
    system.exec("rd " + pDir + " /s /q");
    else
    system.exec("rm -rf " + pDir);
    }

    It does what I want on Windows, but for *nix platforms, I could still see there being a problem removing the directory due to the directory's permissions. But if the script created the directory in the first place, would that be a problem?

    Eric

    ---
    þ Synchronet þ Digital Distortion BBS: digdist.bbsindex.com
  • From Digital Man@VERT to Nightfox on Wed Sep 9 16:30:46 2009
    Re: File deleting & attributes
    By: Nightfox to All on Thu Sep 03 2009 08:50 pm

    I'm working on a JavaScript script for Synchronet that involves extracting an archive into a temporary directory, and then it will recursively delete the temporary directory when it's done.
    My BBS is running in Windows 2000, and it looks like if one of the
    extracted files has the read-only attribute set, file_remove() doesn't remove it. I then started to look into how file attributes are represented in Synchronet's JavaScript model and if it's possible to change them. I noticed that the File class has a property called 'attributes', and there's also a function called file_attrib(), which will give you a file's attributes. The attributes are represented by a number, but the docs don't seem to say what that number means or if there are any variables anywhere that represent different file attributes. I checked sbbsdefs.js and didn't see any mention of file attribute definitions in there.

    So, my questions are:
    1. Is it possible to delete a file regardless of its attributes? And if
    so, how?

    No, you would have to change the attributes first. I would suggest modifying your file extraction command line to strip any read-only attributes.

    2. For File's attribute property and file_attrib()'s return value, what are the attribute values that it can be checked against (or more precisely, where can I find the list of attributes)?

    The attribute bit values are platform specific (e.g. different from Windows and Linux). For example, on Windows:

    #define _A_NORMAL 0x00 /* Normal file - No read/write restrictions */ #define _A_RDONLY 0x01 /* Read only file */
    #define _A_HIDDEN 0x02 /* Hidden file */
    #define _A_SYSTEM 0x04 /* System file */
    #define _A_SUBDIR 0x10 /* Subdirectory */
    #define _A_ARCH 0x20 /* Archive file */

    3. If you wanted to change a file's attributes, can that be done by opening it with the File class, changing its attributes property, and saving the file?

    Yes, but no "saving" is necessary, just close the file.

    digital man

    Snapple "Real Fact" #35:
    Elephants only sleep 2 hours a day.

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net