文件管理器代码Word下载.docx
《文件管理器代码Word下载.docx》由会员分享,可在线阅读,更多相关《文件管理器代码Word下载.docx(26页珍藏版)》请在冰点文库上搜索。
File1.FileName=Text1.Text
Dir1.Path=File1.Path'
设置目录路径
Drive1.Drive=Dir1.Path'
设置驱动器
File1.Pattern=Combo1.Text'
恢复文件显示类型
comdResult=0
BadFilename:
如果没该文件,则显示错误信息
Nosuchfile!
PrivateSubDir1_Change()
File1.Path=Dir1.Path
curFile="
排除删除文件的事件
为诸如更名或删除事件设置变量
curDirec=Dir1.Path
curName=Dir1.Path
PrivateSubDrive1_Change()
DimmsgAsString
OnErrorGoToDrive_er
Dir1.Path=Drive1.Drive
Drive_er:
If(Err=68)Or(Err=71)Then
msg$="
驱动器"
&
Drive1.Drive&
"
未准备好"
MsgBoxmsg$,vbOKOnly
Else
发现未知错误,错误号="
+Str$(Err)
PrivateSubFile1_Click()
'
测试目录后是否有分隔符
IfRight$(Dir1.Path,1)<
>
\"
Then
curFile=Dir1.Path&
File1.FileName
单击文件,可能要进行删除或拷贝操作
curDirec="
waitingCopyFile=File1.FileName
PrivateSubFile1_DblClick()
DimastrAsString
Dimmyopen
astr=Dir1.Path
IfRight(astr,1)<
Thenastr=astr&
myopen=ShellExecute(0,"
open"
astr&
File1.FileName,"
"
1)
PrivateSubCombo1_Change()'
可人工设置文件类型
设置文件列表框的文件显示类型
PrivateSubCombo1_Click()'
用鼠标选取组合框中的文件类型
PrivateSubForm_Load()
装载文件类型
Combo1.AddItem"
*.*"
*.bmp"
*.jpg"
*.exe"
*.doc"
*.txt"
*.mp3"
*.mp4"
*.rmvb"
*.avi"
*.flv"
Command1.Default=True'
设置缺省属性
Text1.Text="
设置在运行时显示在FileListBox中的文件类型
File1.Pattern="
变量初始化
SubDel()
DimmyDir$,reTempDir$
OnErrorGoToerrBad
IfcurFile<
KillcurFile
File1.Refresh'
文件列表更新
IfcurDirec<
reTempDir=curDirec:
myDir$=curDirec
lenfile=Len(reTempDir)
获取上级目录
DoWhilelenfile<
1
IfRight$(reTempDir,1)="
reTempDir=Left$(reTempDir,lenfile-1)
测试是否到了根目录
:
reTempDir=reTempDir&
ExitDo
Loop
Iflenfile=1ThenExitSub
Dir1.Path=reTempDir
ChDirDir1.Path'
返回上级目录
RmDirmyDir$'
需在上级目录进行删除操作
Dir1.Refresh'
目录列表更新
errBad:
If(Err=53)Then
文件不存在"
If(Err=75)Then
目录中还存在文件"
发现错误,错误号="
PrivateSubmnuCopy_Click()
CallCopy
PrivateSubmnuDel_Click()
CallDel
PrivateSubmnuExit_Click()
Reset
End
SubCopy()
copyFile=curFile'
获取拷贝文件名
newCopyFile=waitingCopyFile'
新文件名
SubPaste()
DimfinalFile$
ChDircurDirec'
设置到目的目录
IfRight$(curDirec,1)<
finalFile$=curDirec&
newCopyFile
FileCopycopyFile,finalFile$
File1.Refresh
文件不能自身复制"
SubNewFileDir()
LoadForm2'
装载新建文件夹窗体
Form2.Show1
PrivateSubmnuNewFileDir_Click()
CallNewFileDir
PrivateSubmnuPaste_Click()
CallPaste
PrivateSubmnuRename_Click()
LoadForm3'
装载重命名窗体
Form3.Show1
SubSearch()
IfLabel1.Visible=TrueThen
Label1.Visible=False
Label1.Visible=True
IfText1.Visible=TrueThen
Text1.Visible=False
Else
Text1.Visible=True
EndIf
IfCommand1.Visible=TrueThen
Command1.Visible=False
Command1.Visible=True
PrivateSubmnuSeach_Click()
CallSearch
PrivateSubForm_Resize()
DimH,iAsInteger
OnErrorResumeNext
Resize_ALLMe'
Me是窗体名,Form1,Form2等等都可以
PrivateSubToolbar1_ButtonClick(ByValButtonAsMSComctlLib.Button)
SelectCaseButton.Index
Case1
Case2
CallNewFileDir
Case3
Case4
Case5
EndSelect
Dimmsg$
ChDirForm1.Dir1.Path'
设置到当前路径
MkDirText1.Text
Form1.Dir1.Refresh'
更新目录列表
UnloadForm2'
卸载窗体
路径已经存在或设备未准备好或不存在"
If(Err=76)Then
路径名错误"
PrivateSubCommand2_Click()
UnloadForm2
DimlenPathAsInteger
DimtempName$,msg$
说明点击的是文件列表
IfRight$(curName,1)<
tempName$=curName&
NamecurFileAstempName$&
Text1.Text
Form1.File1.Refresh
Else'
双击的是目录列表
lenPath=Len(curDirec)
tempName$=curDirec
查找上一级目录,以便目录列表更新
DoWhilelenPath<
IfRight$(tempName$,1)="
tempName$=Left$(tempName$,lenPath)
tempName$=Left$(tempName$,lenPath-1)
lenPath=Len(tempName$)
IflenPath=1ThenExitSub
NamecurDirecAstempName$&
tempName$=tempName$&
Form1.Dir1.Path=tempName$
ChDirForm1.Dir1.Path
Form1.Dir1.Refresh
UnloadForm3
PrivateSubClear1()
DimiAsInteger
Fori=0To3
Check1(i).Value=0'
将Check(0)-Check(3)复选框清空
Nexti
PrivateSubShow1(ByValPath1AsString)
UnloadForm4
DimiAsInteger'
存储文件的属性值
i=GetAttr(curFile)'
获取文件的属性值
CallClear1'
调用复选框清空子程序
IfiAndvbNormalThen'
判断是否为常规文件
Check1(0).Value=1'
若是,则常规属性复选框被选中
IfiAndvbReadOnlyThen'
判断是否为只读文件
Check1
(1).Value=1'
若是,则只读属性复选框被选中
IfiAndvbArchiveThen'
判断是否为存档文件
Check1
(2).Value=1'
若是,则存档属性复选框被选中
IfiAndvbHiddenThen'
判断是否为隐藏文件
Check1(3).Value=1'
若是,则隐藏属性复选框被选中
IfCheck1(0).Value=1AndCheck1
(1).Value=1AndCheck1
(2).Value=1AndCheck1(3).Value=1Then
SetAttrcurFile,vbArchive+vbReadOnly+vbNormal+vbHidden
ElseIfCheck1(0).Value=1AndCheck1
(1).Value=1AndCheck1
(2).Value=1Then
SetAttrcurFile,vbArchive+vbReadOnly+vbNormal
ElseIfCheck1(0).Value=1AndCheck1
(1).Value=1AndCheck1(3).Value=1Then
SetAttrcurFile,vbArchive+vbReadOnly+vbHidden
ElseIfCheck1
(1).Value=1AndCheck1
(2).Value=1AndCheck1(3).Value=1Then
SetAttrcurFile,vbReadOnly+vbNormal+vbHidden
ElseIfCheck1(0).Value=1AndCheck1
(1).Value=1Then
SetAttrcurFile,vbArchive+vbReadOnly
ElseIfCheck1(0).Value=1AndCheck1
(2).Value=1Then
SetAttrcurFile,vbArchive+vbNormal
ElseIfCheck1(0).Value=1AndCheck1(3).Value=1Then
SetAttrcurFile,vbArchive+vbHidden
ElseIfCheck1
(1).Value=1AndCheck1
(2).Value=1Then
SetAttrcurFile,vbReadOnly+vbNormal
ElseIfCheck1
(1).Value=1AndCheck1(3).Value=1Then
SetAttrcurFile,vbReadOnly+vbHidden
ElseIfCheck1
(2).Value=1AndCheck1(3).Value=1Then
SetAttrcurFile,vbNormal+vbHidden
ElseIfCheck1(0).Value=1Then
SetAttrcurFile,vbArchive
ElseIfCheck1
(1).Value=1Then
SetAttrcurFile,vbReadOnly
ElseIfCheck1
(2).Value=1Then
SetAttrcurFile,vbNormal
SetAttrcurFile,vbHidden
setAttrcurFile,setAttr
Form1.File1.Refresh'
文件列表更新,若为文件设置了隐藏属性,就看不到了
以下是模块级代码
PubliccurNameAsString'
当前选中的目录名
PubliccurFileAsString'
当前选中的文件
PublicwaitingCopyFileAsString'
待拷贝的文件
PubliccurDirecAsString'
当前选中的目录
PublicTypectrObj
NameAsString
IndexAsLong
ParrentAsString
TopAsLong
LeftAsLong
HeightAsLong
WidthAsLong
ScaleHeightAsLong
ScaleWidthAsLong
EndType
PrivateFormRecord()AsctrObj
PrivateControlRecord()AsctrObj
PrivatebRunningAsBoolean
PrivateMaxFormAsLong
PrivateMaxControlAsLong
PrivateConstWM_NCLBUTTONDOWN=&
HA1
PrivateDeclareFunctionSendMessageLib"
USER32"
SendMessageA"
(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,ByVallParamAsLong)AsLong
PrivateDeclareFunctionReleaseCaptureLib"
()AsLong
FunctionActualPos(plLeftAsLong)AsLong
IfplLeft<
0Then
ActualPos=plLeft+75000
ActualPos=plLeft
EndFunction
FunctionFindForm(pfrmInAsForm)AsLong
DimiAsLong
FindForm=-1
IfMaxForm>
Fori=0To(MaxForm-1)
IfFormRecord(i).Name=pfrmIn.NameThen
FindForm=i
ExitFunction