• 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ãã Mo> js.global.file_copy(dir[i], path1 + backslash()+ dir[i].toLowerCase() +ã Mo> '.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.ãã Mo> js.global.file_copy(dir[i], path1 + backslash()+ dir[i].toLowerCase() +ã Mo> '.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ã