![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-10-31 19:43 |
47,815 topics / 349,930 posts / today 0 new / 48,290 members |
| DOS开发编程 & 发展交流 (开发室) » How to obtain long file names in your own DOS program? |
| Printable Version 3,075 / 16 |
| Floor1 cly119 | Posted 2005-11-06 22:31 |
| 新手上路 Posts 2 Credits 12 | |
|
Compilation environment:
1. DOS of Win98 2. Develop with BC3.1 Please ask for advice from senior experts, thanks! |
|
| Floor2 wuliang6810 | Posted 2005-11-11 18:01 |
| 新手上路 Posts 5 Credits 10 | |
|
Thanks
|
|
| Floor3 qb45 | Posted 2005-11-20 18:14 |
| 高级用户 Posts 194 Credits 677 | |
|
I have the original program for QBASIC to read long files!
|
|
| Floor4 qb45 | Posted 2005-11-20 18:15 |
| 高级用户 Posts 194 Credits 677 | |
|
I don't know if you need it or not?
|
|
| Floor5 bush | Posted 2005-11-21 22:23 |
| 银牌会员 Posts 730 Credits 2,165 | |
|
This is a DOS question, which has nothing to do with the development language, right?
|
|
| Floor6 qb45 | Posted 2005-11-26 11:08 |
| 高级用户 Posts 194 Credits 677 | |
|
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
|
|
| Floor7 qb45 | Posted 2005-11-26 11:18 |
| 高级用户 Posts 194 Credits 677 | |
|
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 DS X=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 DS X=old file address ES I=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 |
|
| Floor8 qb45 | Posted 2005-11-26 11:19 |
| 高级用户 Posts 194 Credits 677 | |
|
I'll also post the 8.3 format modules with the same function. I don't know if everyone needs them.
|
|
| Floor9 JonePeng | Posted 2005-11-26 23:37 |
| 金牌会员 Posts 1,883 Credits 4,562 From 广东广州 | |
|
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.
|
|
| Floor10 qb45 | Posted 2005-11-28 09:29 |
| 高级用户 Posts 194 Credits 677 | |
|
### 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 DX X=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 DS X=old file address ES I=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 DS X=file name return AX=error codefilename$ = 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 DS X=file name, return AX=error codeDIM 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 |
|
| Floor11 qb45 | Posted 2005-11-28 09:30 |
| 高级用户 Posts 194 Credits 677 | |
|
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 ] |
|
| Floor12 wuliang6810 | Posted 2005-12-23 16:45 |
| 新手上路 Posts 5 Credits 10 | |
|
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!
|
|
| Floor13 LiveOnLove | Posted 2005-12-24 15:46 |
| 中级用户 Posts 161 Credits 493 From ZHCN | |
|
Yeah. Written with TC2, there's no way to support long filenames... Oh no.
|
|
| Floor14 qb45 | Posted 2005-12-26 14:09 |
| 高级用户 Posts 194 Credits 677 | |
|
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!
|
|
| Floor15 qb45 | Posted 2005-12-26 14:11 |
| 高级用户 Posts 194 Credits 677 | |
|
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!
|
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |