zl程序教程

您现在的位置是:首页 >  其它

当前栏目

FSO的强大功能

功能 强大 FSO
2023-06-13 09:13:46 时间
<HTML>
<HEAD>
<TITLE>笨狼代码大管家</TITLE>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<style>
body
{
font-size:12;
BACKGROUND:#DADADA;
margin-left:5;
}

.folder
{

font-size:18;
cursor:hand;
}
.folderIcon
{
color:navy;
font-family:wingdings;
font-size:18;
cursor:hand;
}
.file
{
color:navy;
font-size:18;
cursor:hand;
height:21;
}
.fileIcon
{
color:navy;
font-family:wingdings;
font-size:18;
cursor:hand;
height:21;
display:inline;
}
input
{
width:20;
overflow:visible;
border:1pxsolidlightblue;
background-color:#cccccc;
cursor:text;
}
button
{
border:1pxsolidgray;
width:60;
margin-left:2;
cursor:hand;
font-size:12;
filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr="#eaeaff",endColorStr="#618fff",gradientType="0");
}
textarea
{
font-family:Verdana;
width:750;
height:630;
font-size:12px;
overflow:scroll;
}

#frmTree
{
WIDTH:200px;
height:630;
MARGIN:0px;
PADDING:0px;
overflow:scroll;
MARGIN-right:10;
}

#frmSeach
{
WIDTH:200px;
height:630;
MARGIN:0px;
PADDING:0px;
overflow:scroll;
MARGIN-right:10;
}

#hide_control
{
POSITION:absolute;
LEFT:213px;
TOP:10px;
WIDTH:10px;
height:630;
BACKGROUND:#DADADA;
padding-top:300;
cursor:e-resize;
border:1solidgray;
}

#txtFrm
{
POSITION:absolute;
LEFT:230px;
TOP:10px;
WIDTH:100%;
MARGIN:0px;
PADDING:0px;
BACKGROUND:#DADADA;
}
#tab1
{
border:1solid;
cursor:hand;
}
#tab2
{
border:1solid;
cursor:hand;
BACKGROUND:gray;
}
#tab3
{
border:1solid;
cursor:hand;
BACKGROUND:gray;
}
#tab4
{
border:1solid;
cursor:hand;
}
</style>
</HEAD>
<BODYonselectstart="vbs:selectControl"onkeydown="vbs:shortCut">
<divid="frmTree"onclick="vbs:f_Click"onkeydown="vbs:deletFile">
<spanid="tab1"> 目录</span>
<spanid="tab2"onclick="vbs:showMefrmSeach,frmTree"> 搜索</span>
<hr/>
<divid="tree"style="margin-left:0;color:navy;font-size:12;cursor:hand;"></div>
</div>

<divid="frmSeach"onclick="vbs:f_Click">
<spanid="tab3"onclick="vbs:showMefrmTree,frmSeach"> 目录</span>
<spanid="tab4"> 搜索</span>
<hr/>
<divid="list"style="margin-left:0"onkeydown="deletFile">
<inputid="searchKey"style="width:100"/>
<buttononclick="vbs:seachFile"id="searchButton">查找</button><br/>
<divid="seachList"style="margin-left:0">搜索结果</div>
</div>
</div>
<inputtype="button"id="hide_control"onmousedown="vbs:beginDrag"onmouseup="vbs:upHandler"bgcolor="#eeeeee"/>
<divvalign="top"id="txtFrm">
标题:<inputid="articleTitle"style="width:100"readonly/>
<buttonid="browse"onclick="vbs:browseMe">预览</button>
<buttonid="saveButton"onclick="vbs:saveFile">保存</button>
<buttonid="browse"onclick="vbs:createFile">新建</button>
<buttonid="test"onclick="vbs:showHelp">说明</button>
行 <spanid="Ln">1</span>
<textareaid="txt"onkeydown="vbs:TabTxt"onclick="vbs:showLn"></textarea>
</div>


<SCRIPTLANGUAGE="vbscript">
"**************************
"*****超级大笨狼***********
"**************************
onerrorresumenext
window.resizeTowindow.screen.availWidth,window.screen.availHeight
window.moveTo0,0

Setfso=CreateObject("Scripting.FileSystemObject")
dimthisFileDir"定义本文件绝对路径
dimthisFileName"定义本文件名
dimthisFileFolder"定义本文件夹路径


thisFileDir=replace(window.location.href,"file:///","")
thisFileDir=unescape(replace(thisFileDir,"/","\"))
thisFileName=LastOne(thisFileDir,"\")
thisFileFolder=getFolderDir(thisFileDir)
tree.title=thisFileFolder

dimcurrentDir"当前路径
dimcurrentFile"当前文件
dimcurrentDiv"当前DIV对象
dimcurrentSpan"当前Span对象
dimdelatX
dimdragAble:dragAble=false


currentDir=thisFileFolder
setcurrentDiv=tree
tree.innerText=getTxtName(thisFileName)

showMefrmTree,frmSeach
showFoldertree

subshowLn
Ln.innerText=cint((window.event.offsetY-2)/15)+1
endsub

subshortCut

ifwindow.event.keyCode=83andwindow.event.ctrlKeythen
ifcurrentFile<>""thensaveFile
window.event.cancelBubble=true
window.event.returnValue=false
endif
ifwindow.event.keyCode=66andwindow.event.ctrlKeythen
browseMe
window.event.cancelBubble=true
window.event.returnValue=false
endif

ifwindow.event.keyCode=78andwindow.event.ctrlKeythen
createFile
window.event.cancelBubble=true
window.event.returnValue=false
endif

endsub
subbrowseMe
dimwin
setwin=window.open()
win.document.writetxt.value
endsub

subcreateFile
"点创建按钮,真的创建了.
ifvartype(currentSpan)<>0thencurrentSpan.style.color="navy"
ifcurrentDir=""then
"如果点到了文件
currentDir=getFolderDir(currentFile)
else
"点到了文件夹
dimn
setn=currentDiv.nextSibling
do
ifvartype(n)=9thenexitdo
ifleft(n.title,len(currentDir))<>currentDirthenexitdo
setcurrentDiv=n
setn=n.nextSibling
loop
endif
dimre,newFile,s,f

setre=newRegExp
re.Pattern="[^\d]"
re.Global=true
newFile=currentDir&"新收藏"&re.Replace(mid(cstr(now()),3),"")&".txt"
currentFile=newFile"新建文件是当前文件
"构造innerHTML
s="<divclass="file"title=""&newFile
s=s&""style="margin-left:"
ifcurrentDiv.className="file"then
s=s&currentDiv.style.marginLeft&";"> "
else
s=s&px2Int(currentDiv.style.marginLeft)+8&";"> "
endif
s=s&"<spanclass="fileIcon">2"&"</span>"
s=s&"<inputvalue=""
s=s&getTxtName(lastOne(newFile,"\"))&""title=""&getTxtName(lastOne(newFile,"\"))&""onchange="vbs:reNameme"/>"
s=s&"</div>"
"插入innerHTML
currentDiv.insertAdjacentHTML"AfterEnd",s

articleTitle.value=getTxtName(lastOne(newFile,"\"))
txt.value=""
currentDir=""
setcurrentDiv=currentDiv.nextSibling
setcurrentSpan=currentDiv.getElementsByTagName("SPAN")(0)
currentSpan.style.color="red"
"创建文件
setf=fso.CreateTextFile(newFile)
f.close
endsub

functiongetFolderDir(fullDir)
"输入得到全路径,得到文件夹路径
s=LastOne(fullDir,"\")
getFolderDir=left(fullDir,len(fullDir)-len(s))
endfunction

subsaveFile
"保存对文件的修改
Dimst
Setst=fso.OpenTextFile(currentFile,2,True)
st.Writetxt.value
st.close
endsub


subdeletFile
"删除文件
dimn
ifwindow.event.keyCode=46andwindow.event.srcElement.tagName<>"INPUT"then

ifcurrentFile<>""then
ifcurrentFile=thisFileDirthen
alert"不允许删除本文件!"
exitsub
endif
iffso.FileExists(currentFile)then
fso.deletefilecurrentFile,true
currentDiv.parentElement.removeChildcurrentDiv
txt.value=""
currentFile=""
articleTitle.value=""
endif
endif

ifcurrentDir<>""then
ifcurrentDir=thisFileFolderthen
alert"不允许删除根目录!"
exitsub
endif
setn=currentDiv.nextSibling
ifwindow.confirm(currentDir&vbcrlf&"这个文件夹有子文件,你要删除全部子文件吗?")then
do
ifvartype(n)=9thenexitdo
ifpx2Int(n.style.marginLeft)<=px2Int(currentDiv.style.marginLeft)thenexitdo
n.parentElement.removeChildn
setn=currentDiv.nextSibling
loop

iffso.FolderExists(currentDir)thenfso.DeleteFoldercurrentDir
currentDiv.parentElement.removeChildcurrentDiv
endif
endif

endif
endsub

subshowMe(obj1,obj2)
obj1.style.display=""
obj2.style.display="none"
endsub

subbeginDrag
"开始拖拽
delatX=window.event.clientX-px2Int(hide_control.currentStyle.left)
document.attachEvent"onmousemove",getRef("moveHandler")
dragAble=true
window.event.cancelBubble=true
endsub

submoveHandler
"移动绑定事件
ifnotdragAblethenexitsub
dimx
x=window.event.clientX-delatX
hide_control.style.left=x&"px"
frmTree.style.width=abs(x-10)&"px"
frmSeach.style.width=abs(x-10)&"px"
txtFrm.style.left=(x+20)&"px"
window.event.cancelBubble=true
endsub

subupHandler
"放开绑定事件
document.detachEvent"onmousemove",getRef("moveHandler")
dragAble=false
window.event.cancelBubble=true
endsub

functiongetTxtName(fullName)
"去掉文件名后缀
dims:s=lastOne(fullName,".")
getTxtName=left(fullName,len(fullName)-len(s)-1)
endfunction


subreName(obj)
"改名
dimArr,a
Arr=array("/","\",":","*","?",chr(34),"|","<",">")
foreachainArr
ifinstr(obj.value,a)>0then
alert"命名不能含有/\:*?"&chr(34)&"|<>其中的一个"
obj.focus
exitsub
endif
next
dimoldName,newName,oldPath,oldType
oldName=obj.parentElement.title
oldPath=getFolderDir(oldName)
oldType=lastOne(oldName,".")
newName=oldPath&obj.value&"."&oldType
Setf=fso.GetFile(oldName)
f.copynewName
f.deleteTrue
obj.parentElement.title=newName
articleTitle.value=getTxtName(lastOne(newName,"\"))
endsub

FunctionLastOne(Str,splitStr)
"输入字符和分隔符,得到最后一部分
LastOne=right(Str,len(Str)-InStrRev(Str,splitStr))
EndFunction

subselectControl
"控制页面选择的状态
ifwindow.event.srcElement.tagName<>"INPUT"andwindow.event.srcElement.tagName<>"TEXTAREA"then
document.selection.clear
endif
endsub

functionisTXT(fileNameStr)
"判断是否是文本类型的文件
dims,Arr,a,returnValue
returnValue=false
s=lcase(LastOne(fileNameStr,"."))
Arr=array("txt","htm","html","asp","csv","aspx","xml","js","vbs","ini","bat","css","htc","hta","xsl","xslt","sql")
foreachainArr
ifa=sthen
returnValue=true
exitfor
endif
next
isTXT=returnValue
endfunction

subshowFolder(obj)
dimfolderspec:folderspec=obj.title
obj.setAttribute"parsed",true
ifnotfso.FolderExists(folderspec)then
alertfolderspec&"该文件夹不存在,也许是被移动了,所以刷新一下本程序"
window.location.reload
exitsub
endif
dimf,f1,sf,sf1,i,s,fName
setf=fso.GetFolder(folderspec)
setsf=f.Subfolders
re=re&f.name&"\"
s=""
foreachsf1insf
s=s&"<divclass="folder"title=""&sf1.path&"\"style="margin-left:"&cint(replace(obj.style.marginLeft,"px",""))+8&";">"
s=s&"<spanclass="folderIcon">0"&"</span><inputvalue=""&sf1.name&""readonlystyle="cursor:hand;"/></div>"
next

ForEachf1inf.Files
ifisTXT(f1.name)then
s=s&"<divclass="file"title=""&f1.path
s=s&""style="margin-left:"
s=s&px2Int(obj.style.marginLeft)+8&";"> "
s=s&"<spanclass="fileIcon">2"&"</span>"
s=s&"<inputvalue=""
fName=getTxtName(f1.name)
s=s&fName&""title=""&fName&""onchange="vbs:reNameme"/>"
s=s&"</div>"
endif
Next
obj.insertAdjacentHTML"AfterEnd",s
endsub

functionpx2Int(px)
px2Int=cint(replace(px,"px",""))
endfunction

subf_Click()
dimobj,d,f,state
setobj=window.event.srcElement
ifobj.id="searchKey"thenexitsub
ifobj.tagName<>"SPAN"andobj.tagName<>"INPUT"thenexitsub
setcurrentDiv=obj.parentElement
setobj=currentDiv.getElementsByTagName("SPAN")(0)
window.event.cancelBubble=true
selectcaseobj.className
case"folderIcon"
"点到了文件夹
ifvartype(currentSpan)=8then
currentSpan.style.color="navy"
endif
setcurrentSpan=obj
state=abs(cint(obj.innerHTML)-1)
obj.innerHTML=state
obj.style.color="red"
setd=obj.parentElement
currentDir=d.title
currentFile=""
ifd.getAttribute("parsed")=truethen
"合拢

foldd,state
else
"解析
showFolderd
endif


case"fileIcon"
"点到了文件,在textArea里面载入文本文件

ifvartype(currentSpan)=8then
currentSpan.style.color="navy"
endif
setcurrentSpan=obj
obj.style.color="red"
readTextobj.parentElement.title
currentDir=""
currentFile=obj.parentElement.title

endselect
endsub

subfold(o,stateOpen)"合拢
dimn
setn=o.nextSibling
do
ifvartype(n)=9thenexitdo
ifpx2Int(n.style.marginLeft)<=px2Int(o.style.marginLeft)thenexitdo
ifstateOpen=1thenn.style.display=""elsen.style.display="none"
setn=n.nextSibling
loop
endsub


subreadText(filePath)
Dimf,fName

ifnotfso.FileExists(filePath)then
alertfilePath&vbcrlf&"该文件不存在,也许是被移动了,所以刷新一下本程序"
window.location.reload
exitsub
endif

"TXT已经加载的当前文件不再加载.

iffilePath=currentFilethenexitsub
txt.value=""
Setf=fso.OpenTextFile(filePath,1,true)
ifnotf.AtEndOfStreamthen
txt.value=f.readAll
else
txt.value=""
endif
fName=lastOne(filePath,"\")
articleTitle.value=getTxtName(fName)
f.Close
Ln.innerText=1
Endsub

subTabTxt()
"支持tab键的文本框
ifwindow.event.keyCode=38then
ifcint(Ln.innerText)>1thenLn.innerText=cint(Ln.innerText)-1
endif
ifwindow.event.keyCode=40then
Ln.innerText=cint(Ln.innerText)+1
endif

ifwindow.event.keyCode<>9thenexitsub
dimsel,mytext
setsel=document.selection.createRange()
"txt.createTextRange
mytext=sel.text
iflen(mytext)=0then
sel.text=string(4,"")
window.event.cancelBubble=true
window.event.returnValue=false
exitsub
endif

dimt,Arr
t=0
Arr=split(mytext,vbcrlf)
ifwindow.event.shiftKeythen
"按sift
fori=0toubound(Arr)
ifleft(Arr(i),1)=vbtabthen
Arr(i)=mid(Arr(i),2)
t=t+1
else
forj=1to4
ifleft(Arr(i),1)=""then
Arr(i)=mid(Arr(i),2)
t=t+1
else
exitfor
endif
next
endif
next
t=t
else
"不按sift
fori=0toubound(Arr)
Arr(i)=vbtab&Arr(i)
t=t+1
next
endif
mytext=join(Arr,vbcrlf)
sel.text=mytext
sel.collapsetrue
sel.moveEnd"character",0
sel.moveStart"character",(len(mytext)*-1)+t
sel.select()
window.event.cancelBubble=true
window.event.returnValue=false
endsub

"下面是关于搜索
dimseachResult"查找结果
dimnum"结果数量
dimword"搜索关键字

tagStop=false
seachResult=""

subseachFile()
num=0
seachList.innerText="搜索结果"
word=searchKey.value
seachResult=""
iftrim(word)=""then
alert"关键字为空!"
searchKey.focus
exitsub
else
diml
foreachlinlist.getElementsByTagName("DIV")
ifl.id<>"seachList"thenlist.removeChildl
next
seachList.innerText="搜索结果"
seachWordthisFileFolder
seachList.insertAdjacentHTML"AfterEnd",seachResult
seachList.innerText="搜索结果:"&num&"个"
alert"搜索完毕!"
endif
endsub

subseachWord(theFolder)
dimf,f1,st,re,fd,fd1
setf=fso.GetFolder(theFolder)
foreachf1inf.Files
ifisTxt(f1.name)then
ifinstr(f1.name,word)>0then
seachResult=seachResult&"<divclass="file"title=""&f1.path
seachResult=seachResult&""><spanclass="fileIcon">2"&"</span>"
seachResult=seachResult&"<inputvalue=""
fName=getTxtName(f1.name)
seachResult=seachResult&fName&""title=""&fName&"">"
seachResult=seachResult&"</div>"
num=num+1
else
setst=f1.OpenAsTextStream
"逐行读
DoWhilest.AtEndOfStream<>True
ifinstr(st.ReadLine,word)>0then
num=num+1
seachResult=seachResult&"<divclass="file"title=""&f1.path
seachResult=seachResult&""><spanclass="fileIcon">2"&"</span>"
seachResult=seachResult&"<inputvalue=""
fName=getTxtName(f1.name)
seachResult=seachResult&fName&""title=""&fName&"">"
seachResult=seachResult&"</div>"
exitdo
endif
Loop
st.Close
endif
endif
next
setfd=fso.GetFolder(theFolder)
foreachfd1infd.SubFolders
seachWordfd1
next
endsub


subshowHelp
dimmsg
msg="文本代码管理工具【IE5.5以上版本】"&vbcrlf
msg=msg&"------------------------------------------------"&vbcrlf
msg=msg&"使用方法:放到文本类型的文件夹里面,双击运行。"&vbcrlf
msg=msg&"功能:"&vbcrlf
msg=msg&"1,快速浏览,预览CTRL+B,搜索文本类型的文件和代码;"&vbcrlf
msg=msg&"2,按DEL可以删除点中的文件和文件夹;"&vbcrlf
msg=msg&"3,可以修改文件名和文字内容,CTRL+S保存;"&vbcrlf
msg=msg&"4,可以创建文件CTRL+N并且编辑保存;"&vbcrlf
msg=msg&"5,文本编辑支持TAB和shift+TAB键;"&vbcrlf
msg=msg&vbcrlf
msg=msg&"作者:CSDN超级大笨狼[2005/1/18版本]"&vbcrlf
msg=msg&"欢迎传播使用,交流代码panyuguang962@sohu.com"&vbcrlf
msg=msg&"http://superdullwolf.cnzone.net/index.asp"&vbcrlf
alertmsg
endsub
</SCRIPT>

</BODY>
</HTML>