• js.global.file_rename

    From Mortifis@VERT/ALLEYCAT to All on Mon Aug 19 12:53:21 2019
    What is the proper usage of file_rename? I have a script to move and rename files but it doesn't seem to work :-/

    load("sbbsdefs.js");

    if (argc==0)
    path = prompt("Copy/Rename from");
    else
    path = argv[0];

    if (path==undefined) exit();

    if (path.indexOf('*')<0 && path.indexOf('?')<0)
    path += "*"; // No pattern specified

    path1 = prompt("Copy/Rename to");

    if (path1==undefined) exit();

    dir = directory(path,GLOB_PERIOD);

    for (i in dir) {
    if(this.bbs && bbs.sys_status&SS_ABORT) break;
    print('Renaming '+ dir[i] + ' to ' + dir[i].toLowerCase());
    js.global.file_copy(dir[i], path1 + backslash()+ dir[i].toLowerCase() + '.bak');
    mswait(1);
    }

    I also tried with file_rename(...)

    No errors are reported either way.

    Any ideas?



    My doctor said I have the body of a 25 year old ... and the mind of a 10 :-/

    ---
    ■ Synchronet ■ AlleyCat! BBS - http://alleycat.synchro.net:81
  • From echicken@VERT/ECBBS to Mortifis on Mon Aug 19 13:00:37 2019
    Re: js.global.file_rename
    By: Mortifis to All on Mon Aug 19 2019 12:53:21

    js.global.file_copy(dir[i], path1 + backslash()+ dir[i].toLowerCase() + '.bak');

    You don't need to specify js.global except in rare situations. Normally, just saying file_copy or file_rename without prefix is sufficient.

    js.global.file_copy(dir[i], path1 + backslash()+ dir[i].toLowerCase() + '.bak');

    IIRC dir[i] here includes the full path to the file, so your destination (path1 + backslash() + dir[i].toLowerCase() + '.bak') also has it.

    You can use file_getname() to extract just the filename portion of a path:

    file_copy(dir[i], backslash(path1) + file_getname(dir[i]) + '.bak');

    This might achieve what you're looking for.

    Many of these file_* methods return boolean to indicate success/failure, so there may not be an error, but the return value should be false if the operation failed.

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com
    ■ Synchronet ■ electronic chicken bbs - bbs.electronicchicken.com
  • From Digital Man@VERT to Mortifis on Mon Aug 19 13:39:08 2019
    Re: js.global.file_rename
    By: Mortifis to All on Mon Aug 19 2019 12:53 pm

    What is the proper usage of file_rename? I have a script to move and rename files but it doesn't seem to work :-/

    load("sbbsdefs.js");

    if (argc==0)
    path = prompt("Copy/Rename from");
    else
    path = argv[0];

    if (path==undefined) exit();

    if (path.indexOf('*')<0 && path.indexOf('?')<0)
    path += "*"; // No pattern specified

    path1 = prompt("Copy/Rename to");

    if (path1==undefined) exit();

    dir = directory(path,GLOB_PERIOD);

    for (i in dir) {
    if(this.bbs && bbs.sys_status&SS_ABORT) break;
    print('Renaming '+ dir[i] + ' to ' + dir[i].toLowerCase());
    js.global.file_copy(dir[i], path1 + backslash()+
    dir[i].toLowerCase() + '.bak');
    mswait(1);
    }

    I also tried with file_rename(...)

    No errors are reported either way.

    You have to check the return value of file_rename() to know whether it succeeded or not. If it fails (returns false), then the global errno/errno_str properties could indicate why it failed.

    Any ideas?

    The proper usage of file_rename is file_rename(path/oldname, path/newname) (like it says at http://synchro.net/docs/jsobjs.html), so without knowing the values of the arguments you're passing and the state of your file system(s), I can't guess. I suggest printing some debug output to find out what's going on.

    digital man

    This Is Spinal Tap quote #24:
    David St. Hubbins: You're a haughty one, saucy Jack.
    Norco, CA WX: 84.1°F, 51.0% humidity, 8 mph NE wind, 0.00 inches rain/24hrs

    ---
    ■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net
  • From Mortifis@VERT/ALLEYCAT to echicken on Tue Aug 20 10:22:57 2019
    This might achieve what you're looking for.

    Many of these file_* methods return boolean to indicate success/failure, so there may not be an error, but the return value should be false if the operation failed.


    LOL! I realized later that I was having another DUH! moment and that my command was working, just copying to the same location is was copying or renaming from and I wasn't changing the case of the file name :/

    I was trying to write a script to help someone who posted about copying files from a CD on a linuxbox; I posted the script in a reply to him but others came up with better solutions :-)

    Thanks for the help EC

    My doctor said I have the body of a 25 year old ... and the mind of a 10 :-/

    ---
    ■ Synchronet ■ AlleyCat! BBS - http://alleycat.synchro.net:81
  • From Mortifis@VERT/ALLEYCAT to Digital Man on Tue Aug 20 10:25:00 2019

    The proper usage of file_rename is file_rename(path/oldname, path/newname) (like it says at http://synchro.net/docs/jsobjs.html), so without knowing the values of the arguments you're passing and the state of your file system(s), I can't guess. I suggest printing some debug output to find out what's going on.

    digital man

    I am still learning, thank you for the help, the script was doing what I asked, I just didn't script it to do what I wanted LOL I have a better handle on it now :-)

    Thank you for the help DM


    My doctor said I have the body of a 25 year old ... and the mind of a 10 :-/

    ---
    ■ Synchronet ■ AlleyCat! BBS - http://alleycat.synchro.net:81