Console Compiler 2 NAME (Rename) Bug
Author |
Message |
spa.. #1 / 3
|
Console Compiler 2 NAME (Rename) Bug
Can Anyone offer a Solution to this foul tasting bug? A Console Compiler 2 bug has stopped me dead in my tracks! I'm a new user of the Console Compiler and have had some experience in writing basic code in the past. My first project using the console compiler was to write a rename utility program that will remove the garbage and overhead from the long filenames created from newsgroups headers. Many of these names are very long, sometimes 160 characters in length. This is the problem: If the original filename is longer than 119 characters, the NAME function fails to rename the file and no error condition is reported. Is there a fix or work-around for this problem? I'd hate to think that I wasted a week of work because of a bug in this compiler. Below is a sample filename that I could not rename using compiled code from the Console Compiler; however, Windows Explorer has no trouble renaming it. The filename is 120 characters long. Remove one or more characters from it (even from the file extension), and the NAME function in powerbasic will then rename it. (AM_Gold_Series)_(AM_Gold_The_Mid_1960's_Classics)_Dusty_Springfield_-_I_Only_Want_To_Be_With_You,_File_185_(01_17).mp3_ Here's a portion of the code I'm using to do the clean-up and rename: #COMPILE EXE FUNCTION PBMAIN() LOCAL A AS STRING LOCAL CMD AS STRING LOCAL E AS STRING LOCAL Q AS STRING LOCAL I AS INTEGER LOCAL R AS INTEGER LOCAL W1 AS INTEGER LOCAL W2 AS INTEGER CURSOR OFF : R = 3 LOCATE R,1 CONSOLE SCREEN 25,131 'Path is passed to COMMAND$ from Windows Explorer CMD = COMMAND$ + "\" Path$ = CMD + "*.*" A = DIR$(Path$) : IF ERR > 0 THEN GOTO DispErr Begin: IF LEN(A)=0 THEN Done CLS : Q = A REPLACE "_" WITH " " IN Q Q = TRIM$(Q,ANY " _") I = INSTR(-1,Q,".") IF I = 0 THEN E = "" ELSE E = RIGHT$(Q,LEN(Q)-I+1) Q = LEFT$(Q,I-1) DO W1=INSTR(1,Q,"(") : W2=INSTR(1,Q,")") IF (W1>0 AND W2>0) THEN Q=STRDELETE$(Q,W1,W2-W1+1) LOOP UNTIL W1 = 0 REPLACE " " WITH " " IN Q Q = TRIM$(Q) Q = Q + E IF Q <> A THEN LOCATE R,1 : PRINT "Renaming: LEN(A) = ";LEN(A); LOCATE R+2,1 : PRINT A; LOCATE R+5,1 : PRINT "To:"; LOCATE R+7,1 : PRINT Q; Q = CMD + Q : A = CMD + A : NAME A AS Q END IF A = DIR$ IF ERR = 0 THEN Begin ELSE DispErr DispErr: SELECT CASE ERR LOCATE R+10,1 CASE 52 : PRINT " Bad Filename! "; CASE 53 : PRINT " File Not Found! "; CASE 54 : PRINT " Bad File Mode "; CASE 55 : PRINT " File is in Use! "; CASE 57 : PRINT " Device IO Error! "; CASE 58 : PRINT " File Already Exists! "; CASE 61 : PRINT " Disk is Full! "; CASE 62 : PRINT " Input Past End! "; CASE 63 : PRINT " Bad Record Number! "; CASE 64 : PRINT " Bad File Name! "; CASE 67 : PRINT " Too Many Files! "; CASE 68 : PRINT " Device Unavailable "; CASE 70 : PRINT " Permission Denied! "; CASE 71 : PRINT " Disk Not Ready! "; CASE 72 : PRINT " Disk Media Error! "; CASE 74 : PRINT " Rename Across Disks! "; CASE 75 : PRINT " Path/File Access Error! "; CASE 76 : PRINT " Path Not Found! "; CASE ELSE : PRINT " Error# ";ERR; END SELECT LOCATE R+12,1 : PRINT "Job Aborted!" : PRINT Done: WAITKEY$ END FUNCTION Anyone have a solution? Thanks!
|
Mon, 25 Aug 2003 09:50:37 GMT |
|
|
Lance Edmon #2 / 3
|
Console Compiler 2 NAME (Rename) Bug
I tested your code and a variation that targets the NAME statement explicitly. I tested this under Windows 2000, and it creates and renames the exact file name you specified, without any errors. Try this for yourself: FUNCTION PBMAIN c$ = CURDIR$ c$ = RTRIM$(c$, "\") + "\" a$ = "(AM_Gold_Series)_(AM_Gold_The_Mid_1960's_Classics)_Dusty_Springfield_-_I_Only_Want_To_Be_With_You,_File_185_(01_17).mp3" OPEN c$ + a$ FOR OUTPUT AS #1 PRINT #1, "test" CLOSE #1 b$ = a$ REPLACE "_" WITH " " IN b$ NAME c$ + a$ AS b$ a$ = DIR$(b$) PRINT c$ + a$ WAITKEY$ END FUNCTION Note that this code does not perform any error testing, and I note that your code does not test for an error immediately after the NAME statement either. Maybe you could try adding: ON ERROR GOTO DISPERR To your code (and probably an appropriate RESUME statement if you want to retry after an error). BTW, which operating system are you using to test your code with? Quote:
>Can Anyone offer a Solution to this foul tasting bug? >A Console Compiler 2 bug has stopped me dead in my tracks! >I'm a new user of the Console Compiler and have had some >experience in writing basic code in the past. My first project using >the console compiler was to write a rename utility program that will >remove the garbage and overhead from the long filenames created >from newsgroups headers. Many of these names are very long, sometimes >160 characters in length. This is the problem: >If the original filename is longer than 119 characters, the NAME >function fails to rename the file and no error condition is reported. >Is there a fix or work-around for this problem? I'd hate to think that >I wasted a week of work because of a bug in this compiler. >Below is a sample filename that I could not rename using compiled code >from the Console Compiler; however, Windows Explorer has no trouble >renaming it. The filename is 120 characters long. Remove one or more >characters from it (even from the file extension), and the NAME >function in PowerBasic will then rename it. >(AM_Gold_Series)_(AM_Gold_The_Mid_1960's_Classics)_Dusty_Springfield_-_I_Only_Want_To_Be_With_You,_File_185_(01_17).mp3_ >Here's a portion of the code I'm using to do the clean-up and rename: >#COMPILE EXE >FUNCTION PBMAIN() >LOCAL A AS STRING >LOCAL CMD AS STRING >LOCAL E AS STRING >LOCAL Q AS STRING >LOCAL I AS INTEGER >LOCAL R AS INTEGER >LOCAL W1 AS INTEGER >LOCAL W2 AS INTEGER >CURSOR OFF : R = 3 >LOCATE R,1 >CONSOLE SCREEN 25,131 >'Path is passed to COMMAND$ from Windows Explorer >CMD = COMMAND$ + "\" >Path$ = CMD + "*.*" >A = DIR$(Path$) : IF ERR > 0 THEN GOTO DispErr >Begin: >IF LEN(A)=0 THEN Done >CLS : Q = A >REPLACE "_" WITH " " IN Q >Q = TRIM$(Q,ANY " _") >I = INSTR(-1,Q,".") >IF I = 0 THEN E = "" ELSE E = RIGHT$(Q,LEN(Q)-I+1) >Q = LEFT$(Q,I-1) >DO >W1=INSTR(1,Q,"(") : W2=INSTR(1,Q,")") >IF (W1>0 AND W2>0) THEN Q=STRDELETE$(Q,W1,W2-W1+1) >LOOP UNTIL W1 = 0 >REPLACE " " WITH " " IN Q >Q = TRIM$(Q) >Q = Q + E >IF Q <> A THEN >LOCATE R,1 : PRINT "Renaming: LEN(A) = ";LEN(A); >LOCATE R+2,1 : PRINT A; >LOCATE R+5,1 : PRINT "To:"; >LOCATE R+7,1 : PRINT Q; >Q = CMD + Q : A = CMD + A : NAME A AS Q >END IF >A = DIR$ >IF ERR = 0 THEN Begin ELSE DispErr >DispErr: >SELECT CASE ERR >LOCATE R+10,1 >CASE 52 : PRINT " Bad Filename! "; >CASE 53 : PRINT " File Not Found! "; >CASE 54 : PRINT " Bad File Mode "; >CASE 55 : PRINT " File is in Use! "; >CASE 57 : PRINT " Device IO Error! "; >CASE 58 : PRINT " File Already Exists! "; >CASE 61 : PRINT " Disk is Full! "; >CASE 62 : PRINT " Input Past End! "; >CASE 63 : PRINT " Bad Record Number! "; >CASE 64 : PRINT " Bad File Name! "; >CASE 67 : PRINT " Too Many Files! "; >CASE 68 : PRINT " Device Unavailable "; >CASE 70 : PRINT " Permission Denied! "; >CASE 71 : PRINT " Disk Not Ready! "; >CASE 72 : PRINT " Disk Media Error! "; >CASE 74 : PRINT " Rename Across Disks! "; >CASE 75 : PRINT " Path/File Access Error! "; >CASE 76 : PRINT " Path Not Found! "; >CASE ELSE : PRINT " Error# ";ERR; >END SELECT >LOCATE R+12,1 : PRINT "Job Aborted!" : PRINT >Done: >WAITKEY$ >END FUNCTION >Anyone have a solution? >Thanks!
Lance PowerBASIC Support ------------------------------------------------------------------------- PowerBASIC, Inc. | 800-780-7707 Sales | "We put the Power in Basic!" 316 Mid Valley Center | 831-659-8000 Voice | http://www.powerbasic.com
|
Mon, 25 Aug 2003 18:31:16 GMT |
|
|
Fred Oxenb #3 / 3
|
Console Compiler 2 NAME (Rename) Bug
Try to use following: NAME Chr$(34) & A & Chr$(34) AS Chr$(34) & Q & Chr$(34) ------- That is "makePathPretty" if sourcepath contain a space-character! Fred
Quote: > Can Anyone offer a Solution to this foul tasting bug? > A Console Compiler 2 bug has stopped me dead in my tracks! > I'm a new user of the Console Compiler and have had some > experience in writing basic code in the past. My first project using > the console compiler was to write a rename utility program that will > remove the garbage and overhead from the long filenames created > from newsgroups headers. Many of these names are very long, sometimes > 160 characters in length. This is the problem: > If the original filename is longer than 119 characters, the NAME > function fails to rename the file and no error condition is reported. > Is there a fix or work-around for this problem? I'd hate to think that > I wasted a week of work because of a bug in this compiler. > Below is a sample filename that I could not rename using compiled code > from the Console Compiler; however, Windows Explorer has no trouble > renaming it. The filename is 120 characters long. Remove one or more > characters from it (even from the file extension), and the NAME > function in PowerBasic will then rename it.
(AM_Gold_Series)_(AM_Gold_The_Mid_1960's_Classics)_Dusty_Springfield_-_I_On l y_Want_To_Be_With_You,_File_185_(01_17).mp3_ Quote: > Here's a portion of the code I'm using to do the clean-up and rename: > #COMPILE EXE > FUNCTION PBMAIN() > LOCAL A AS STRING > LOCAL CMD AS STRING > LOCAL E AS STRING > LOCAL Q AS STRING > LOCAL I AS INTEGER > LOCAL R AS INTEGER > LOCAL W1 AS INTEGER > LOCAL W2 AS INTEGER > CURSOR OFF : R = 3 > LOCATE R,1 > CONSOLE SCREEN 25,131 > 'Path is passed to COMMAND$ from Windows Explorer > CMD = COMMAND$ + "\" > Path$ = CMD + "*.*" > A = DIR$(Path$) : IF ERR > 0 THEN GOTO DispErr > Begin: > IF LEN(A)=0 THEN Done > CLS : Q = A > REPLACE "_" WITH " " IN Q > Q = TRIM$(Q,ANY " _") > I = INSTR(-1,Q,".") > IF I = 0 THEN E = "" ELSE E = RIGHT$(Q,LEN(Q)-I+1) > Q = LEFT$(Q,I-1) > DO > W1=INSTR(1,Q,"(") : W2=INSTR(1,Q,")") > IF (W1>0 AND W2>0) THEN Q=STRDELETE$(Q,W1,W2-W1+1) > LOOP UNTIL W1 = 0 > REPLACE " " WITH " " IN Q > Q = TRIM$(Q) > Q = Q + E > IF Q <> A THEN > LOCATE R,1 : PRINT "Renaming: LEN(A) = ";LEN(A); > LOCATE R+2,1 : PRINT A; > LOCATE R+5,1 : PRINT "To:"; > LOCATE R+7,1 : PRINT Q; > Q = CMD + Q : A = CMD + A : NAME A AS Q > END IF > A = DIR$ > IF ERR = 0 THEN Begin ELSE DispErr > DispErr: > SELECT CASE ERR > LOCATE R+10,1 > CASE 52 : PRINT " Bad Filename! "; > CASE 53 : PRINT " File Not Found! "; > CASE 54 : PRINT " Bad File Mode "; > CASE 55 : PRINT " File is in Use! "; > CASE 57 : PRINT " Device IO Error! "; > CASE 58 : PRINT " File Already Exists! "; > CASE 61 : PRINT " Disk is Full! "; > CASE 62 : PRINT " Input Past End! "; > CASE 63 : PRINT " Bad Record Number! "; > CASE 64 : PRINT " Bad File Name! "; > CASE 67 : PRINT " Too Many Files! "; > CASE 68 : PRINT " Device Unavailable "; > CASE 70 : PRINT " Permission Denied! "; > CASE 71 : PRINT " Disk Not Ready! "; > CASE 72 : PRINT " Disk Media Error! "; > CASE 74 : PRINT " Rename Across Disks! "; > CASE 75 : PRINT " Path/File Access Error! "; > CASE 76 : PRINT " Path Not Found! "; > CASE ELSE : PRINT " Error# ";ERR; > END SELECT > LOCATE R+12,1 : PRINT "Job Aborted!" : PRINT > Done: > WAITKEY$ > END FUNCTION > Anyone have a solution? > Thanks!
|
Sun, 31 Aug 2003 05:13:22 GMT |
|
|
|