China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 18:42
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » How to obtain long file names in your own DOS program? View 2,617 Replies 16
Original Poster Posted 2005-11-06 22:31 ·  中国 广东 惠州 惠城区 电信
新手上路
Credits 12
Posts 2
Joined 2005-11-06 22:21
20-year member
UID 44713
Gender Male
Status Offline
Compilation environment:
1. DOS of Win98
2. Develop with BC3.1
Please ask for advice from senior experts, thanks!
Floor 2 Posted 2005-11-11 18:01 ·  中国 贵州 贵阳 电信
新手上路
Credits 10
Posts 5
Joined 2005-11-11 17:58
20-year member
UID 45069
Gender Male
Status Offline
Thanks
Floor 3 Posted 2005-11-20 18:14 ·  中国 湖北 宜昌 电信
高级用户
★★
Credits 677
Posts 194
Joined 2003-09-13 00:00
22-year member
UID 9778
Gender Male
Status Offline
I have the original program for QBASIC to read long files!
Floor 4 Posted 2005-11-20 18:15 ·  中国 湖北 宜昌 电信
高级用户
★★
Credits 677
Posts 194
Joined 2003-09-13 00:00
22-year member
UID 9778
Gender Male
Status Offline
I don't know if you need it or not?
Floor 5 Posted 2005-11-21 22:23 ·  中国 重庆 渝中区 电信
银牌会员
★★★
Credits 2,165
Posts 730
Joined 2004-04-21 00:00
22-year member
UID 22966
Gender Male
Status Offline
This is a DOS question, which has nothing to do with the development language, right?
Floor 6 Posted 2005-11-26 11:08 ·  中国 湖北 宜昌 电信
高级用户
★★
Credits 677
Posts 194
Joined 2003-09-13 00:00
22-year member
UID 9778
Gender Male
Status Offline
Although DOS does not provide a list of long filenames, there are still many third - party programs to solve this problem. If we understand the principle, we can program by ourselves to solve it
Floor 7 Posted 2005-11-26 11:18 ·  中国 湖北 宜昌 电信
高级用户
★★
Credits 677
Posts 194
Joined 2003-09-13 00:00
22-year member
UID 9778
Gender Male
Status Offline
Example of displaying long file names: Programming language qbasic 4.5, running environment DOS 7.1, DOS under win98
COMMON SHARED Filedta AS STRING * 500
DIM SHARED filefindhandle%
FileName$ = "*.*" 'Display all files
FileAttrib% = &HFF 'Display all attributes
PRINT GetFileList$("*.*", &HFF, FileNum%) 'Call module
PRINT FileNum% 'Display the number of files

FUNCTION ChangeDir% (DirName$)
'Change long directory
ax% = 0: Bx% = 1: Cx% = 2: Dx% = 3: bp% = 4
Si% = 5: di% = 6: Flags% = 7: Ds% = 8: es% = 9
DIM Reg%(9)
DirName$ = DirName$ + CHR$(0)
Reg%(Ds%) = VARSEG(DirName$)
Reg%(Dx%) = SADD(DirName$)
Reg%(ax%) = &H713B
CALL INT86XOLD(&H21, Reg%(), Reg%())
ChangeDir% = Reg%(Flags%) AND 1
END FUNCTION

DEFINT A-Z
'Changes current drive.
FUNCTION ChangeDrive% (Drive$)
'Change drive letter: entry AH=0E DL=0A,1B..
'ax% = 0: bx% = 1: cx% = 2: dx% = 3: bp% = 4
'si% = 5: di% = 6: flags% = 7: ds% = 8: es% = 9
DIM Reg%(9)
Drive$ = UCASE$(Drive$)
Reg%(0) = &HE00
Reg%(3) = ASC(Drive$) - 65
CALL INT86XOLD(&H21, Reg%(), Reg%())
ChangeDrive% = -1
END FUNCTION

DEFSNG A-Z
SUB CloseFile (FileHandle%)
'Close file handle
'ax% = 0: bx% = 1: cx% = 2: dx% = 3: bp% = 4
'si% = 5: di% = 6: flags% = 7: ds% = 8: es% = 9
DIM Reg%(9)
Reg%(1) = FileHandle%
Reg%(0) = &H3E00
CALL INT86XOLD(&H21, Reg%(), Reg%())
END SUB

FUNCTION CreateDir% (DirName$)
'Create long directory
ax% = 0: Bx% = 1: Cx% = 2: Dx% = 3: bp% = 4
Si% = 5: di% = 6: Flags% = 7: Ds% = 8: es% = 9
DIM Reg%(9)
DirName$ = DirName$ + CHR$(0)
Reg%(Ds%) = VARSEG(DirName$)
Reg%(Dx%) = SADD(DirName$)
Reg%(ax%) = &H7139
CALL INT86XOLD(&H21, Reg%(), Reg%())
CreateDir% = Reg%(Flags%) AND 1
END FUNCTION

FUNCTION CreateFile% (FileName$)
'Create long file
ax% = 0: Bx% = 1: Cx% = 2: Dx% = 3: bp% = 4
Si% = 5: di% = 6: Flags% = 7: Ds% = 8: es% = 9
FileName$ = FileName$ + CHR$(0)
DIM Reg%(9)
Reg%(Ds%) = VARSEG(FileName$)
Reg%(Si%) = SADD(FileName$)
Reg%(Cx%) = &H20
Reg%(Bx%) = 2
Reg%(Dx%) = &H10
Reg%(ax%) = &H716C
CALL INT86XOLD(&H21, Reg%(), Reg%())
CreateFile% = -1
IF (Reg%(Flags%) AND 1) = 0 THEN CreateFile% = Reg%(ax%)
END FUNCTION

DEFINT A-Z
FUNCTION CurrentDrive$
'Get current drive letter: entry AH=19 returns AL=0A,1B...
'ax% = 0: bx% = 1: cx% = 2: dx% = 3: bp% = 4
'si% = 5: di% = 6: flags% = 7: ds% = 8: es% = 9
DIM Reg%(9)
Drive$ = UCASE$(Drive$)
Reg%(0) = &H1900
CALL INT86XOLD(&H21, Reg%(), Reg%())
a% = Reg%(0)
CurrentDrive$ = CHR$(65 + (Reg%(0) AND &HFF))
END FUNCTION

FUNCTION CurrentPath$ (DeviceNum%)
'Get current path: entry AH=7147 DL=00 Current, 1A,1B... returns DS:SI address=path string
'ax% = 0: bx% = 1: cx% = 2: dx% = 3: bp% = 4
'si% = 5: di% = 6: flags% = 7: ds% = 8: es% = 9
DIM PathSize AS STRING * 255
DIM Reg%(9)
Reg%(0) = &H7147
Reg%(3) = DeviceNum%
Reg%(8) = VARSEG(PathSize)
Reg%(5) = VARPTR(PathSize)
CALL INT86XOLD(&H21, Reg%(), Reg%())
CurrentPath$ = LEFT$(PathSize, INSTR(PathSize, CHR$(0)) - 1)
END FUNCTION

DEFSNG A-Z
FUNCTION DelDir% (DirName$)
'Delete long directory
ax% = 0: Bx% = 1: Cx% = 2: Dx% = 3: bp% = 4
Si% = 5: di% = 6: Flags% = 7: Ds% = 8: es% = 9
DIM Reg%(9)
DirName$ = DirName$ + CHR$(0)
Reg%(Ds%) = VARSEG(DirName$)
Reg%(Dx%) = SADD(DirName$)
Reg%(ax%) = &H713A
CALL INT86XOLD(&H21, Reg%(), Reg%())
DelDir% = Reg%(Flags%) AND 1
END FUNCTION

FUNCTION DelFile% (FileName$, FileAttrib%)
'Delete file
ax% = 0: Bx% = 1: Cx% = 2: Dx% = 3: bp% = 4
Si% = 5: di% = 6: Flags% = 7: Ds% = 8: es% = 9
DIM Reg%(9)
FileName$ = FileName$ + CHR$(0)
Reg%(Ds%) = VARSEG(FileName$)
Reg%(Dx%) = SADD(FileName$)
Reg%(Si%) = 0
Reg%(Cx%) = FileAttrib%
Reg%(ax%) = &H7141
CALL INT86XOLD(&H21, Reg%(), Reg%())
DleDir% = Reg%(Flags%) AND 1
END FUNCTION

DEFINT A-Z
FUNCTION FindDrives% (Drive$)
'Find disk
'ax% = 0: bx% = 1: cx% = 2: dx% = 3: bp% = 4
'si% = 5: di% = 6: flags% = 7: ds% = 8: es% = 9
DIM Reg%(9)
Reg%(0) = &H440E
Reg%(1) = ASC(Drive$) - 64
CALL INT86XOLD(&H21, Reg%(), Reg%())
IF (Reg%(7) AND 1) = 1 THEN
FindDrives% = -1
ELSE
FindDrives% = Reg%(0) AND 255
END IF
END FUNCTION

FUNCTION FindFirstFile% (FileName$, FileAttrib%)
'ax% = 0: bx% = 1: cx% = 2: dx% = 3: bp% = 4
'si% = 5: di% = 6: flags% = 7: ds% = 8: es% = 9
FileName$ = FileName$ + CHR$(0)
DIM Reg%(9)
Reg%(0) = &H714E
Reg%(5) = 0
Reg%(9) = VARSEG(Filedta)
Reg%(6) = VARPTR(Filedta)
Reg%(8) = VARSEG(FileName$)
Reg%(3) = SADD(FileName$)
Reg%(2) = FileAttrib%
CALL INT86XOLD(&H21, Reg%(), Reg%())
FindFirstFile% = 1
IF (Reg%(7) AND 1) = 0 THEN FindFirstFile% = Reg%(0)
END FUNCTION

FUNCTION FindNextFile%
'If the search is successful, call to find the next file. Entry AH=4F DSX=file name, return AX=error code
DIM Reg%(9)
Reg%(0) = &H714F
Reg%(1) = filefindhandle%
Reg%(9) = VARSEG(Filedta)
Reg%(6) = VARPTR(Filedta)
CALL INT86XOLD(&H21, Reg%(), Reg%())
FindNextFile% = Reg%(7) AND 1
END FUNCTION

DEFSNG A-Z
FUNCTION GetDir$
'Get long directory list
DIM DirTem AS STRING * 12 ' Temp AS STRING * 12
'SetFileDta
FileName$ = "*.*"
FileAttrib% = &HFF
IF FindFirstFile%(FileName$, FileAttrib%) = 1 THEN EXIT FUNCTION
DO
Find% = INSTR(31, Filedta$, CHR$(0)) - 31
FileName$ = MID$(Filedta$, 31, Find%)
FileAttrib% = CVI((MID$(Filedta$, 21, 2)))
IF FileAttrib% = 4096 THEN
MID$(DirTem, 1, 12) = FileName$
Temp$ = Temp$ + DirTem
END IF
LOOP WHILE FindNextFile% = 0
GetDir$ = Temp$
END FUNCTION

DEFINT A-Z
FUNCTION GetFileList$ (FileName$, FileAttrib%, FileNum%)
'Get long file list
IF FileName$ = "" THEN FileName$ = "*.*"
FileName$ = FileName$ + CHR$(0)
DIM Reg%(9)
Reg%(0) = &H714E
Reg%(5) = 0
Reg%(9) = VARSEG(Filedta)
Reg%(6) = VARPTR(Filedta)
Reg%(8) = VARSEG(FileName$)
Reg%(3) = SADD(FileName$)
Reg%(2) = FileAttrib%
CALL INT86XOLD(&H21, Reg%(), Reg%())
IF (Reg%(7) AND 1) = 1 THEN EXIT FUNCTION
FFh% = Reg%(0)
i% = 0
DO
Find% = INSTR(&H2D, Filedta, CHR$(0)) - &H2C
FileName$ = MID$(Filedta, &H2D, Find%)
Reg%(0) = &H714F
Reg%(1) = FFh%
CALL INT86XOLD(&H21, Reg%(), Reg%())
Flags% = Reg%(7) AND 1
Temp$ = Temp$ + FileName$
i% = i% + 1
LOOP UNTIL Flags% = 1
GetFileList$ = Temp$
FileNum% = i%
END FUNCTION

FUNCTION NumDrives%
'Return the number of logical drives
FOR i% = 0 TO 25
IF FindDrives%(CHR$(i% + 65)) = -1 THEN
NumDrives% = i% - 1
EXIT FOR
END IF
NEXT i%
END FUNCTION

DEFSNG A-Z
FUNCTION OpenFile% (FileName$, OpenMode%, FileHandle%)
'ReadMode% 0,Read 1,Write 2,Read/Write 4,Read(No change Time)
'OpenMode% 1,Open file 2,ClsFile and Open 10h NoFile To Create File
ax% = 0: Bx% = 1: Cx% = 2: Dx% = 3: bp% = 4
Si% = 5: di% = 6: Flags% = 7: Ds% = 8: es% = 9
FileName$ = FileName$ + CHR$(0)
DIM Reg%(9)
Reg%(Ds%) = VARSEG(FileName$)
Reg%(Si%) = SADD(FileName$)
Reg%(Cx%) = &H20 'FileAttrib
Reg%(Bx%) = 2 'ReadMode
Reg%(Dx%) = OpenMode%
Reg%(ax%) = &H716C
CALL INT86XOLD(&H21, Reg%(), Reg%())
OpenFile% = Reg%(Flags%) AND 1
FileHandle% = Reg%(ax%)
END FUNCTION

FUNCTION ReadFile% (Buff$, ReadLen%, FileHandle%)
DIM Reg%(9)
IF Buff$ = "" THEN Buff$ = SPACE$(ReadLen%)
Reg%(8) = VARSEG(Buff$)
Reg%(3) = SADD(Buff$)
Reg%(0) = &H3F00
Reg%(1) = FileHandle%
Reg%(2) = ReadLen%
CALL INT86XOLD(&H21, Reg%(), Reg%())
ReadFile% = Reg%(7) AND 1
ReadLen% = Reg%(0)
END FUNCTION

FUNCTION RenFile% (OldFile$, NewFile$)
'Rename file: entry AH=56 DSX=old file address ESI=new
'ax% = 0: bx% = 1: cx% = 2: dx% = 3: bp% = 4
'si% = 5: di% = 6: flags% = 7: ds% = 8: es% = 9
DIM Reg%(9)
OldFile$ = OldFile$ + CHR$(0)
NewFile$ = NewFile$ + CHR$(0)
Reg%(8) = VARSEG(OldFile$)
Reg%(3) = SADD(OldFile$)
Reg%(9) = VARSEG(NewFile$)
Reg%(6) = SADD(NewFile$)
Reg%(0) = &H7156
CALL INT86XOLD(&H21, Reg%(), Reg%())
FileRen% = Reg%(0)
END FUNCTION

FUNCTION WriteFile% (Buff$, WriteLen%, FileHandle%)
ax% = 0: Bx% = 1: Cx% = 2: Dx% = 3: bp% = 4
Si% = 5: di% = 6: Flags% = 7: Ds% = 8: es% = 9
DIM Reg%(9)
Reg%(Ds%) = VARSEG(Buff$)
Reg%(Dx%) = SADD(Buff$)
Reg%(Bx%) = FileHandle%
Reg%(Cx%) = WriteLen%
Reg%(ax%) = &H4000
CALL INT86XOLD(&H21, Reg%(), Reg%())
WriteFile% = Reg%(Flags%) AND 1
WriteLen% = Reg%(Cx%)
END FUNCTION
Floor 8 Posted 2005-11-26 11:19 ·  中国 湖北 宜昌 电信
高级用户
★★
Credits 677
Posts 194
Joined 2003-09-13 00:00
22-year member
UID 9778
Gender Male
Status Offline
I'll also post the 8.3 format modules with the same function. I don't know if everyone needs them.
Floor 9 Posted 2005-11-26 23:37 ·  中国 广东 广州 海珠区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
Nice! Please the original poster continue to post 8.3 format modules. Hope that when the original poster posts a post with the source code, the source code is posted in the form of "insert code", otherwise those strange expressions will appear.
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 10 Posted 2005-11-28 09:29 ·  中国 湖北 宜昌 电信
高级用户
★★
Credits 677
Posts 194
Joined 2003-09-13 00:00
22-year member
UID 9778
Gender Male
Status Offline
### Functions that these modules can complete
1. Get current drive letter
2. Get current path
3. Find files
4. Rename files

Startup please use QB/L

**Usage of CurrentDrive$**
Example: PRINT CurrentDrive$
Can display the current drive letter

**Usage of CurrentPath$**
Example: PRINT CurrentPath$
Can display the current path

**Usage of FindFirstFile% (filename$, FileAttrib%)**
In the entry, filename$ is the file name to be found, and FileAttrib% is the attribute of the file to be found. Before finding the file, the buffer must be set. If you want to find whether there is a QB.EXE file in the current directory
Example:
DIM SHARED FileDta$ 'Define the buffer as a global shared variable
SetFileDta 'Set buffer
IF FindFirstFile% ("QB.EXE", &hFF) THEN PRINT "File found"

**Usage of RenFile% (OldFile$, NewFile$)**
OldFile$ is the file name to be renamed, NewFile$ is the name you want to change it to. If you want to change TEST.BAS in the current directory to TEST.TXT
Example:
OldFile$="TEST.BAS"
NewFile$="TEST.TXT"
IF RenFile% (OldFile$, NewFile$) THEN PRINT "File renamed successfully"

Also can display all files in the current directory, so no example is given here!

SUB SetFileDta
'Set DTA: entry AH=1A DXX=buffer (32)
FileDta$ = STRING$(43, CHR$(0))
DIM Reg%(9)
Reg%(0) = &H1A00
Reg%(8) = VARSEG(FileDta$)
Reg%(3) = SADD(FileDta$)
CALL INT86XOLD(&H21, Reg%(), Reg%())
END SUB


FUNCTION RenFile% (OldFile$, NewFile$)
'File rename: entry AH=56 DSX=old file address ESI=new
'ax% = 0: bx% = 1: cx% = 2: dx% = 3: bp% = 4
'si% = 5: di% = 6: flags% = 7: ds% = 8: es% = 9
DIM Reg%(9)
OldFile$ = OldFile$ + CHR$(0)
NewFile$ = NewFile$ + CHR$(0)
Reg%(8) = VARSEG(OldFile$)
Reg%(3) = SADD(OldFile$)
Reg%(9) = VARSEG(NewFile$)
Reg%(6) = SADD(NewFile$)
Reg%(0) = &H5600
CALL INT86XOLD(&H21, Reg%(), Reg%())
FileRen% = Reg%(0)
END FUNCTION

FUNCTION FindFirstFile% (filename$, FileAttrib%)
'Find the first file: entry AH=4E CX=attribute DSX=file name return AX=error code
filename$ = filename$ + CHR$(0)
DIM Reg%(9)
Reg%(0) = &H4E00
Reg%(8) = VARSEG(filename$)
Reg%(3) = SADD(filename$)
Reg%(2) = FileAttrib%
CALL INT86XOLD(&H21, Reg%(), Reg%())
FindFirstFile% = Reg%(7) AND 1
END FUNCTION

FUNCTION FindNextFile%
'If the search is successful, call to search for the next file entry AH=4F DSX=file name, return AX=error code
DIM Reg%(9)
Reg%(0) = &H4F00
CALL INT86XOLD(&H21, Reg%(), Reg%())
FindNextFile% = Reg%(7) AND 1
END FUNCTION

FUNCTION CurrentPath$
'Get current path: entry AH=47 DL=0A,1B... return DS:SI address=path string
'ax% = 0: bx% = 1: cx% = 2: dx% = 3: bp% = 4
'si% = 5: di% = 6: flags% = 7: ds% = 8: es% = 9
DIM PathSize AS STRING * 64
DIM Reg%(9)
Reg%(0) = &H4700
Reg%(3) = ASC(CurrentDrive$) - 64
Reg%(8) = VARSEG(PathSize)
Reg(5) = VARPTR(PathSize)
CALL INT86XOLD(&H21, Reg%(), Reg%())
CurrentPath$ = LEFT$(PathSize, INSTR(PathSize, CHR$(0)) - 1)
END FUNCTION


FUNCTION CurrentDrive$
'Get current drive letter: entry AH=19 return AL=0A,1B...
'ax% = 0: bx% = 1: cx% = 2: dx% = 3: bp% = 4
'si% = 5: di% = 6: flags% = 7: ds% = 8: es% = 9
DIM Reg%(9)
Drive$ = UCASE$(Drive$)
Reg%(0) = &H1900
CALL INT86XOLD(&H21, Reg%(), Reg%())
A% = Reg%(0)
CurrentDrive$ = CHR$(65 + (Reg%(0) AND &HFF))
END FUNCTION
Floor 11 Posted 2005-11-28 09:30 ·  中国 湖北 宜昌 电信
高级用户
★★
Credits 677
Posts 194
Joined 2003-09-13 00:00
22-year member
UID 9778
Gender Male
Status Offline
Where is the code inserted?? Why can't I see it???

All the codes I sent above must be used under DOS or WIN98, and absolutely do not run on systems with nt kernel such as xp or 2000!!!

The program with long file names is written according to the programming materials in this forum!

[ Last edited by qb45 on 2005-11-28 at 09:34 ]
Floor 12 Posted 2005-12-23 16:45 ·  中国 贵州 贵阳 电信
新手上路
Credits 10
Posts 5
Joined 2005-11-11 17:58
20-year member
UID 45069
Gender Male
Status Offline
I'm writing a program with TC, and I want to generate a long filename for my own data. I don't know how to solve it. I'm a newbie. I haven't used QB for a long time. Friends who have solved it with C, please let me know. Thanks!
Floor 13 Posted 2005-12-24 15:46 ·  中国 广东 珠海 电信
中级用户
★★
Credits 493
Posts 161
Joined 2002-10-29 00:00
23-year member
UID 94
Gender Male
From ZHCN
Status Offline
Yeah. Written with TC2, there's no way to support long filenames... Oh no.
Floor 14 Posted 2005-12-26 14:09 ·  中国 湖北 宜昌 电信
高级用户
★★
Credits 677
Posts 194
Joined 2003-09-13 00:00
22-year member
UID 9778
Gender Male
Status Offline
In fact, TC 2.0 can also be fully used. As long as you know how to use the DOS interrupt call functions of TC, you can make it too. However, it is a bit more troublesome than QBASIC!
Floor 15 Posted 2005-12-26 14:11 ·  中国 湖北 宜昌 电信
高级用户
★★
Credits 677
Posts 194
Joined 2003-09-13 00:00
22-year member
UID 9778
Gender Male
Status Offline
There are ready-made materials about interrupt calls for long file names in this forum! My code is written according to the programming materials in this forum! I also want to thank the netizens who posted the materials!
Forum Jump: