DOS BAT file equivalent to Unix basename command?

前端 未结 8 1290
野趣味
野趣味 2020-12-03 00:43

Is there an easy way to get to the basename (file name without extension) of a DOS file name using the DOS BAT command language?

I agree: format c:\\ is

相关标签:
8条回答
  • 2020-12-03 01:33

    DOS 6.22 does not support %~nI in for batch statements. here's a workaround to the problem I presented in my original question about isql's 4.10 bcheck utility requiring only a basename whereas in isql 2.10 bcheck utility worked with star.star as an argument. I created the following QBASIC program to solve bcheck 4.10 now requiring only a basename to work:

    BatFile$ = "CHKFILE.BAT"
            IF INSTR(COMMAND$, "?") > 0 THEN
              PRINT
              PRINT "This program generates a batch file to check Informix files"
              PRINT "  -b  BBBB.BAT    this option is used to change the batch file name"
              PRINT "                  by default the batch file name is CHKFILE.BAT"
              PRINT
              SYSTEM
            END IF
            IF INSTR(COMMAND$, "-B") > 0 THEN
              BatFile$ = LTRIM$(MID$(COMMAND$, INSTR(COMMAND$, "-B") + 2)) + "  "
              BatFile$ = LEFT$(BatFile$, INSTR(BatFile$, " ") - 1)
            END IF
    
            OPEN BatFile$ FOR OUTPUT AS #2
    
    
            filename$ = DIR$("*.dat")
            IF LEN(filename$) = 0 THEN SYSTEM
            DO WHILE LEN(filename$) > 0
              PRINT #2, "bcheck -y", filename$
              filename$ = DIR$
            LOOP
            CLOSE
            SYSTEM
    

    OR, one can write an ACE program to extract the basename from systables.dirpath and PRINT "BCHECK -y ",systables.dirpath

    0 讨论(0)
  • 2020-12-03 01:35

    I understand that the answer "you can't" is not good enough. So, if it really /has/ to be done in Real Mode DOS, then get the 4DOS command shell and accompanying programs and use it instead of COMMAND.COM

    http://www.4dos.info/v4dos.htm

    I haven't used it in years, but it was always /far/ better than COMMAND.COM If you search this page: http://www.4dos.info/4batfaq.htm for "basename" you will see there is a Real Mode DOS answer to your problem if using 4DOS /instead/ of COMMAND.COM

    The only other solution path I can think of is to find or write a Real Mode .exe that performs basename.

    COMMAND.COM, even in DOS 6.22 with all its supporting external commands, was always an incredibly crippled system for scripts/batch files. Note that the MinGW32 command line progs will be of no help. All that stuff is for Protected Mode (32 bit Windows). If you try it in DOS you'll just get the cryptic "This program cannot be run in DOS mode." or something similar.

    0 讨论(0)
提交回复
热议问题