|
cly119
新手上路
积分 12
发帖 2
注册 2005-11-6
状态 离线
|
『楼 主』:
如何在自己的DOS程序中取得长文件名?
编译环境:
1.Win98的DOS
2.使用BC3.1来开发
请高手指教,多谢!
|
|
2005-11-6 22:31 |
|
|
wuliang6810
新手上路
积分 10
发帖 5
注册 2005-11-11
状态 离线
|
『第
2 楼』:
我也遇到同样问题,请高手不怜辞教
谢谢
|
|
2005-11-11 18:01 |
|
|
qb45
高级用户
积分 677
发帖 194
注册 2003-9-13
状态 离线
|
|
2005-11-20 18:14 |
|
|
qb45
高级用户
积分 677
发帖 194
注册 2003-9-13
状态 离线
|
|
2005-11-20 18:15 |
|
|
bush
银牌会员
积分 2165
发帖 730
注册 2004-4-21
状态 离线
|
『第
5 楼』:
這是個dos問題,與開發語言無關吧?
|
|
2005-11-21 22:23 |
|
|
qb45
高级用户
积分 677
发帖 194
注册 2003-9-13
状态 离线
|
|
2005-11-26 11:08 |
|
|
qb45
高级用户
积分 677
发帖 194
注册 2003-9-13
状态 离线
|
『第
7 楼』:
'显示长文件名的例子:编程语言qbasic 4.5,运行环境DOS7.1,win98下DOS
COMMON SHARED Filedta AS STRING * 500
DIM SHARED filefindhandle%
FileName$ = "*.*" '要显示所有文件
FileAttrib% = &HFF '显示所有属性
PRINT GetFileList$("*.*", &HFF, FileNum%) '调用模块
PRINT FileNum% '显示文件数
FUNCTION ChangeDir% (DirName$)
'更改长目录
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$)
'改变盘符:入口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%)
'关闭文件句柄
'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$)
'建立长目录
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$)
'建立长文件
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$
'获得当前盘符:入口AH=19 返回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%)
'获得当前路径:入口AH=7147 DL=00 Current, 1A,1B... 返回DS:SI地址=路径字符串
'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$)
'删除长目录
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%)
'删除文件
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$)
'查找磁盘
'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%
'查找成功根据调用查找下一个文件 入口AH=4F DSX=文件名,返回AX=错误码
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$
'获得长目录列表
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%)
'获得长文件列表
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%
'返回逻辑盘符的数量
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$)
'文件改名:入口AH=56 DSX=旧文件地址 ESI=新
'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
|
我(QB45)的照片与简历
http://www.programfan.com/club/showbbs.asp?id=197280
|
|
2005-11-26 11:18 |
|
|
qb45
高级用户
积分 677
发帖 194
注册 2003-9-13
状态 离线
|
|
2005-11-26 11:19 |
|
|
JonePeng
金牌会员
D◎$ Fαп
积分 4562
发帖 1883
注册 2004-1-19 来自 广东广州
状态 离线
|
『第
9 楼』:
不错!请楼主继续发8.3格式的模块吧。希望楼主发带有源程序的帖子时把源程序以“插入代码”形式发表,不然会出现那些奇怪的表情。
|
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
|
|
2005-11-26 23:37 |
|
|
qb45
高级用户
积分 677
发帖 194
注册 2003-9-13
状态 离线
|
『第
10 楼』:
这些模块可以完成的功能
1 获得当前盘符
2 获得当前路径
3 查找文件
4 文件改名
启动请用QB/L
CurrentDrive$的用法
例: PRINT CurrentDrive$
可以显示当前的盘符
CurrentPath$
例RINT CurrentPath$
可以显示当前的路径
FindFirstFile% (filename$, FileAttrib%)的用法
入口中filename$是要找的文件名 FileAttrib%为要找文件的属性
在找文件以前必须设置缓冲
如果要找当前目录下有没有QB.EXE这个文件
例:
DIM SHARED FileDta$ '定义缓冲区为全局共享变量
SetFileDta '设置缓冲
IF FindFirstFile% ("QB.EXE", &hFF) THEN PRINT "找到文件"
RenFile% (OldFile$, NewFile$)的用法
OldFile$,为要改名的文件名 NewFile$为你要改名字
如果你要把当前目录下的TEST.BAS 改名为 TEST.TXT
例:
OldFile$="TEST.BAS"
NewFile$="TEST.TXT"
IF RenFile% (OldFile$, NewFile$) THEN PRINT "文件改名成功"
还可以显示当前目录下所有文件,这里就不举例了!
SUB SetFileDta
'设置DTA:入口AH=1A DXX=缓冲区(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$)
'文件改名:入口AH=56 DSX=旧文件地址 ESI=新
'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%)
'查找第一个文件:入口AH=4E CX=属性 DSX=文件名 返回AX=错误码
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%
'查找成功根据调用查找下一个文件 入口AH=4F DSX=文件名,返回AX=错误码
DIM Reg%(9)
Reg%(0) = &H4F00
CALL INT86XOLD(&H21, Reg%(), Reg%())
FindNextFile% = Reg%(7) AND 1
END FUNCTION
FUNCTION CurrentPath$
'获得当前路径:入口AH=47 DL=0A,1B... 返回DS:SI地址=路径字符串
'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$
'获得当前盘符:入口AH=19 返回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
|
我(QB45)的照片与简历
http://www.programfan.com/club/showbbs.asp?id=197280
|
|
2005-11-28 09:29 |
|
|
qb45
高级用户
积分 677
发帖 194
注册 2003-9-13
状态 离线
|
|
2005-11-28 09:30 |
|
|
wuliang6810
新手上路
积分 10
发帖 5
注册 2005-11-11
状态 离线
|
『第
12 楼』:
感谢楼上的兄弟
我是用TC写 的程序,我希望能把自己的数据生成一个长文件名,不知道如何解决,菜鸟一个,QB很久没用了,有通过C解决的朋友说一声,谢谢!
|
|
2005-12-23 16:45 |
|
|
LiveOnLove
中级用户
积分 493
发帖 161
注册 2002-10-29 来自 ZHCN
状态 离线
|
『第
13 楼』:
是啊。用TC2写的,没有办法支持长文件名。。。晕了。
|
|
2005-12-24 15:46 |
|
|
qb45
高级用户
积分 677
发帖 194
注册 2003-9-13
状态 离线
|
|
2005-12-26 14:09 |
|
|
qb45
高级用户
积分 677
发帖 194
注册 2003-9-13
状态 离线
|
|
2005-12-26 14:11 |
|
|