Ejemplos de cargar la lista de directorios MS-DOS en una matriz

Exención de responsabilidades de contenido KB retirado

Este artículo se refiere a productos para los que Microsoft ya no ofrece soporte técnico. Por tanto, el presente artículo se ofrece "tal cual" y no será actualizado.

Resumen

Este artículo describe tres métodos diferentes de colocar un directorio del disco de MS-DOS en una matriz de cadenas.


Ejemplo 1 muestra cómo utilizar la función de $ DIR para leer una lista en una matriz de directorios. Esto es probablemente el método más sencillo para su uso con Visual Basic para MS-DOS. Las funciones de $ DIR se introdujo en PDS básica de Microsoft para MS-DOS y MS OS/2, versión 7.0. Para obtener un ejemplo del uso de la función de $ DIR (que funciona en MS-DOS y MS OS/2), consulta la Base de conocimientos en las siguientes palabras clave:
7.0 y "DIR$" y directorio y anuncio
Ejemplo 2 muestra un método sencillo para SHELL al comando DIR de MS-DOS, redirigir la salida a un archivo y del archivo de entrada en variables de cadena.


Ejemplo 3 siguiente muestra cómo cargar un listado de directorios del disco de MS-DOS en una matriz de cadenas, utilizando llamar a interrumpir la instrucción para invocar el sistema operativo MS-DOS interrupción 21h, con funciones 1Ah (SetDTA), 4Eh (FindFirst) y 4Fh (BuscarSiguiente).

Más información

Para obtener un ejemplo de llamada a las funciones de interrupción de MS-DOS para obtener la información de directorio de disco de Microsoft QuickBasic para MS-DOS, versiones 2.0, 2.01 o 3.0, consulta la Base de conocimientos en las siguientes palabras clave:
INT86. OBJ y FINDFIRST
Para un PDS básica de Microsoft para MS-DOS y MS OS/2, versión 7.0 o 7.1 o Basic Compiler de Microsoft para MS-DOS y MS OS/2, ejemplo de versión 6.0 o 6.0b que muestra la información de directorio en modo protegido para MS OS/2, consulte Knowledge Base en las siguientes palabras clave:
DosFindFirst o DosFindNext

Ejemplo 1

' To try this example in VBDOS.EXE:' 1. From the File menu, choose New Project.
' 2. Copy the code example to the Code window.
' 3. Press F5 to run the program.
DEFINT A-Z
CONST TRUE = -1
CONST FALSE = NOT TRUE
NumFiles = 255 ' Maximum number of filenames to hold.
Counter = 0
Finished = FALSE
DIM FileName$(NumFiles)

CLS ' Enter DIR type filespec, for example "C:\*.BAS":
INPUT "Enter filespec:"; Path$
TempName$ = DIR$(Path$) ' Get the first filename.
IF TempName$ = "" THEN
PRINT "No file(s) found"
ELSE
FileName$(Counter) = TempName$ ' Keep getting filenames until we
Counter = Counter + 1 ' have NumFiles worth or we get
DO ' them all.
TempName$ = DIR$
IF TempName$ <> "" THEN FileName$(Counter) = TempName$
Counter = Counter + 1
LOOP WHILE TempName$ <> "" AND Counter <= NumFiles
END IF
IF FileName$(0) <> "" THEN ' Display filenames if we received
Counter = 0 ' any.
DO
PRINT FileName$(Counter)
IF FileName$(Counter) = "" THEN Finished = TRUE
Counter = Counter + 1
LOOP WHILE Counter <= NumFiles AND NOT Finished
END IF
END

Ejemplo 2

' To try this example in VBDOS.EXE:' 1. From the File menu, choose New Project.
' 2. Copy the code example to the Code window.
' 3. Press F5 to run the program.
'
' This example works in QuickBasic for MS-DOS, versions 2.0, 2.01, 3.0,
' 4.0, 4.0b, and 4.5; and Basic Compiler for MS-DOS and MS OS/2,
' versions 6.0 and 6.0b; and Basic PDS for MS-DOS and MS OS/2,
' versions 7.0 and 7.1.

nf = 200 ' Handles directory listing up to 200 lines.
DIM buffer$(nf)
INPUT "Enter Search Path: ", path$ ' Enter path such as c:
SHELLSTRING$ = "dir " + path$ + " >dirfile.dat"
SHELL SHELLSTRING$ ' SHELL to the MS-DOS DIRectory command.
OPEN "dirfile.dat" FOR INPUT AS #1
pntr% = 0
WHILE NOT EOF(1) AND pntr% < nf
pntr% = pntr% + 1
INPUT #1, buffer$(pntr%) ' Inputs one directory line at a time.
PRINT buffer$(pntr%)
WEND
CLOSE #1
KILL "dirfile.dat"
END

Ejemplo 3

' To try this example in VBDOS.EXE:' 1. From the File menu, choose New Project.
' 2. Copy the code example to the Code window.
' 3. Press F5 to run the program.

' To run this program in the environment, you must invoke the
' environment with the /L switch to load the default Quick library:
' VBDOS.EXE /L for Visual Basic 1.0 for MS-DOS

' Use the following include file for Visual Basic 1.0 for MS-DOS:
REM $INCLUDE: 'VBDOS.BI'
' This examples works in QuickBasic for MS-DOS, versions 4.0, 4.0b,
' and 4.0; and Basic Compiler for MS-DOS and MS OS/2 (real mode only),
' versions 6.0 and 6.0b.

' Use the following include file for QuickBasic for MS-DOS:
REM $INCLUDE: 'QB.BI'

TYPE FileFindBuf
dos AS STRING * 21
Attributes AS STRING * 1
CreateTime AS INTEGER
AccessDate AS INTEGER
FileSize AS LONG
FileName AS STRING * 13
END TYPE
TYPE FileInfo
FileName AS STRING * 13
Size AS STRING * 8
Seconds AS STRING * 4
Minutes AS STRING * 4
Hours AS STRING * 4
Day AS STRING * 4
Month AS STRING * 4
Year AS STRING * 5
END TYPE
DIM BUFFER AS FileFindBuf
DIM FileInfoBlock(100) AS FileInfo
DECLARE SUB intbuf (BUFFER AS FileFindBuf)
DECLARE SUB setdta (BUFFER AS FileFindBuf)
DECLARE FUNCTION firstfm! (path$, fa%)
DECLARE FUNCTION nextfm ()
DECLARE SUB CalculateAssign (FileInfoBlock() AS ANY, BUFFER AS ANY,_
counter!)
DECLARE SUB PrintDirList (FileInfoBlock() AS ANY, i!)
CLS : CALL setdta(BUFFER)
INPUT "Enter the files spec: "; path$
fa% = 0 ' A value of 16 includes directory names.
counter = 0
IF (firstfm(path$, fa%) = 0) THEN
DO
counter = counter + 1
CalculateAssign FileInfoBlock(), BUFFER, counter
CALL setdta(BUFFER)
LOOP WHILE (nextfm = 0)
END IF

CLS
FOR i = 1 TO counter
PrintDirList FileInfoBlock(), i
NEXT i

END

SUB CalculateAssign (FileInfoBlock() AS FileInfo, _
BUFFER AS FileFindBuf, counter)
FileInfoBlock(counter).FileName = BUFFER.FileName
FileInfoBlock(counter).Size = STR$(BUFFER.FileSize)
FileInfoBlock(counter).Seconds = STR$(BUFFER.CreateTime AND &H1F)
FileInfoBlock(counter).Minutes = _
STR$((BUFFER.CreateTime AND &H7E0) \ 32)
' If BUFFER.CreateTime is negative add 64K to make unsigned integer:
IF BUFFER.CreateTime < 0 THEN
FileInfoBlock(counter).Hours = _
STR$(((BUFFER.CreateTime + 2 ^ 16) AND &HF800) \ 2048)
ELSE
FileInfoBlock(counter).Hours = _
STR$((BUFFER.CreateTime AND &HF800) \ 2048)
END IF
FileInfoBlock(counter).Day = STR$(BUFFER.AccessDate AND &H1F)
FileInfoBlock(counter).Month = _
STR$((BUFFER.AccessDate \ 32) AND &HF)
FileInfoBlock(counter).Year = _
STR$((BUFFER.AccessDate \ 512) + 1980)
END SUB

FUNCTION firstfm (path$, fa%)
DIM inreg AS regtypeX, outreg AS regtypeX
' Use regtype for QuickBasic.
inreg.ax = &H4E00
inreg.cx = fa%
FileName$ = path$ + CHR$(0)
inreg.dx = SADD(FileName$)
inreg.ds = SSEG(FileName$)
' Use CALL INTERRUPT in QuickBasic for MS-DOS.
CALL INTERRUPTX (&H21, inreg, outreg)
firstfm = (outreg.ax AND &HF)
END FUNCTION

SUB intbuf (BUFFER AS FileFindBuf) STATIC
' The first 20 bytes are reserved for MS-DOS and are unchanged.
BUFFER.CreateTime = 0
BUFFER.Attributes = " "
BUFFER.AccessDate = 0
BUFFER.FileSize = 0
BUFFER.FileName = STRING$(13, 32)
END SUB

FUNCTION nextfm
DIM inreg AS regtype, outreg AS regtype
inreg.ax = &H4F00
CALL interrupt(&H21, inreg, outreg)
nextfm = outreg.ax AND &HF
END FUNCTION

SUB PrintDirList (FileInfoBlock() AS FileInfo, i)
PRINT FileInfoBlock(i).FileName;
PRINT SPACE$(5); FileInfoBlock(i).Size;
PRINT SPACE$(5); RTRIM$(LTRIM$(FileInfoBlock(i).Month)) + "-";
IF LEN(RTRIM$(LTRIM$(FileInfoBlock(i).Day))) = 1 THEN
FileInfoBlock(i).Day = "0" + LTRIM$(FileInfoBlock(i).Day)
END IF
PRINT RTRIM$(LTRIM$(FileInfoBlock(i).Day)) + "-";
PRINT RTRIM$(LTRIM$(FileInfoBlock(i).Year));
IF VAL(FileInfoBlock(i).Hours) = 0 THEN
FileInfoBlock(i).Hours = STR$(12) ' Change midnight from 0 to 12.
END IF
IF VAL(FileInfoBlock(i).Hours) > 12 THEN
x% = VAL(FileInfoBlock(i).Hours) - 12
FileInfoBlock(i).Hours = STR$(x%)
suffix$ = "p"
ELSE
suffix$ = "a"
END IF
IF VAL(FileInfoBlock(i).Hours) = 12 AND_
VAL(FileInfoBlock(i).Minutes) > 0 THEN
suffix$ = "p"
END IF
IF LEN(RTRIM$(LTRIM$(FileInfoBlock(i).Hours))) = 1 THEN
t% = 7
ELSE
t% = 6
END IF
PRINT SPACE$(t%); RTRIM$(LTRIM$(FileInfoBlock(i).Hours)) + ":";
IF LEN(RTRIM$(LTRIM$(FileInfoBlock(i).Minutes))) = 1 THEN
FileInfoBlock(i).Minutes = "0" + LTRIM$(FileInfoBlock(i).Minutes)
END IF
PRINT RTRIM$(LTRIM$(FileInfoBlock(i).Minutes));
PRINT suffix$
END SUB

SUB setdta (BUFFER AS FileFindBuf) STATIC
DIM inreg AS regtypex, outreg AS regtypex
CALL intbuf(BUFFER)
inreg.ax = &H1A00
inreg.ds = VARSEG(BUFFER)
inreg.dx = VARPTR(BUFFER)
CALL interruptx(&H21, inreg, outreg)
END SUB

Propiedades

Id. de artículo: 41447 - Última revisión: 17 ene. 2017 - Revisión: 1

Comentarios