<%
dim myfilefolder
set myfilefolder = new filefoldercls
response.write myfilefolder.moveafile(“f:\123\4561.exe”,”f:\123\4562.txt”)
response.write myfilefolder.moveafolder(“f:\456″,”f:\ditg\456”)
response.write myfilefolder.showfilesystemtype(“i:\”)
response.write myfilefolder.copyafile(“f:\123\4562.txt”,”f:\123\4563.txt”)
!!!!
response.write myfilefolder.copyafolder(“f:\123\”,”f:\789\”)
response.write myfilefolder.showfolderlist(“f:\ditg”)
response.write myfilefolder.showfilelist(“f:\123\123”)
response.write myfilefolder.deleteafile(“f:\123\4562.txt”)
response.write myfilefolder.deleteafolder(“f:\456\”)
response.write myfilefolder.createfolderdemo(“f:\147\”)
response.write myfilefolder.getfilesize(“f:\123\4563.txt”)
response.write myfilefolder.getfoldersize(“f:\123\123.txt”)
response.write myfilefolder.showfileaccessinfo(“f:\123\123.txt”,1)&”<br>”
response.write myfilefolder.showfileaccessinfo(“f:\123\123.txt”,2)&”<br>”
response.write myfilefolder.showfileaccessinfo(“f:\123\123.txt”,3)&”<br>”
response.write myfilefolder.showfileaccessinfo(“f:\123\123.txt”,4)&”<br>”
response.write myfilefolder.showfileaccessinfo(“f:\123\123.txt”,5)&”<br>”
response.write myfilefolder.showfileaccessinfo(“f:\123\123.txt”,6)&”<br>”
response.write myfilefolder.showfileaccessinfo(“f:\123\123.txt”,7)&”<br>”
response.write myfilefolder.showfileaccessinfo(“f:\123\123.txt”,8)&”<br>”
response.write myfilefolder.showfolderaccessinfo(“f:\123\”,1)&”<br>”
response.write myfilefolder.showfolderaccessinfo(“f:\123\”,2)&”<br>”
response.write myfilefolder.showfolderaccessinfo(“f:\123\”,3)&”<br>”
response.write myfilefolder.showfolderaccessinfo(“f:\123\”,4)&”<br>”
response.write myfilefolder.showfolderaccessinfo(“f:\123\”,5)&”<br>”
response.write myfilefolder.showfolderaccessinfo(“f:\123\”,6)&”<br>”
response.write myfilefolder.showfolderaccessinfo(“f:\123\”,7)&”<br>”
response.write myfilefolder.showfolderaccessinfo(“f:\123\”,8)&”<br>”
response.write myfilefolder.writetxtfile(“f:\123\cexo.txt”,””,1)&”<br>”
response.write myfilefolder.writetxtfile(“f:\123\cexo.txt”,”cexowxfdw”,1)&”<br>”
response.write myfilefolder.writetxtfile(“f:\123\cexo.txt”,chr(13)&chr(10)
&”cexowxfdw”,2)&”<br>”
response.write myfilefolder.readtxtfile(“f:\123\cexo.txt”)&”<br>”
response.write myfilefolder.displayleveldepth(“f:\ditg\ditg\bumen\images”)&”<br>”
class filefoldercls
public fso
private sub class_initialize()
set fso = createobject(“scripting.filesystemobject”)
end sub
private sub class_terminate()
set fso = nothing
end sub
//==================================文件操作==================================
取文件大小
function getfilesize(filename)
//功能:取文件大小
//形参:文件名
//返回值:成功为文件大小,失败为-1
//
dim f
if reportfilestatus(filename) = 1 then
set f = fso.getfile(filename)
getfilesize = f.size
else
getfilesize = -1
end if
end function
文件删除
function deleteafile(filespec)
//功能:文件删除
//形参:文件名
//返回值:成功为1,失败为-1
//
if reportfilestatus(filespec) = 1 then
fso.deletefile(filespec)
deleteafile = 1
else
deleteafile = -1
end if
end function
显示文件列表
function showfilelist(folderspec)
//功能:目录存在时显示此目录下的所有文件
//形参:目录名
//返回值:成功为文件列表,失败为-1
//
dim f, f1, fc, s
if reportfolderstatus(folderspec) = 1 then
set f = fso.getfolder(folderspec)
set fc = f.files
for each f1 in fc
s = s & f1.name
s = s & “|”
next
showfilelist = s
else
showfilelist = -1
end if
end function
!!!
文件复制
function copyafile(sourcefile,destinationfile)
//功能:源文件存在时,才能对文件进行复制,目的文件无影响
//形参:源文件,目的文件
//返回值:成功为1,失败为-1
//
dim myfile
if reportfilestatus(sourcefile) = 1 then
set myfile = fso.getfile(sourcefile)
myfile.copy (destinationfile)
copyafile = 1
else
copyafile = -1
end if
end function
文件移动
response.write moveafile(“f:\123\4561.exe”,”f:\123\4562.txt”)
function moveafile(sourcefile,destinationfile)
//功能:源文件存在时目的文件不存在时才能对文件进行移动
//形参:源文件,目的文件
//返回值:成功为1,失败为-1
//
if reportfilestatus(sourcefile)=1 and reportfilestatus(destinationfileorpath) =
-1 then
fso.movefile sourcefile,destinationfileorpath
moveafile = 1
else
moveafile = -1
end if
end function
文件是否存在?
response.write reportfilestatus(“g: oft\delphi\my_pro\代码库.exe”)
function reportfilestatus(filename)
//功能:判断文件是否存在
//形参:文件名
//返回值:成功为1,失败为-1
//
dim msg
msg = -1
if (fso.fileexists(filename)) then
msg = 1
else
msg = -1
end if
reportfilestatus = msg
end function
文件创建日期
response.write showdatecreated(“g: oft\delphi\my_pro\代码库.exe”)
response.write showdatecreated(“g: oft\delphi\my_pro\复件 代码库.exe”)
function showdatecreated(filespec)
//功能:文件创建日期
//形参:文件名
//返回值:成功:文件创建日期,失败:-1
//
dim f
if reportfilestatus(filespec) = 1 then
set f = fso.getfile(filespec)
showdatecreated = f.datecreated
else
showdatecreated = -1
end if
end function
文件属性
response.write getattributes(“g: oft\delphi\my_pro\复件 代码库.exe”)
function getattributes(filename)
//功能:显示文件属性
//形参:文件名
//返回值:成功:文件属性,失败:-1
//
dim f,str
if reportfilestatus(filename) = 1 then
set f = fso.getfile(filename)
select case f.attributes
case 0 str=”普通文件。没有设置任何属性。 “
case 1 str=”只读文件。可读写。 “
case 2 str=”隐藏文件。可读写。 “
case 4 str=”系统文件。可读写。 “
case 16 str=”文件夹或目录。只读。 “
case 32 str=”上次备份后已更改的文件。可读写。 ”
case 1024 str=”链接或快捷方式。只读。 “
case 2048 str=” 压缩文件。只读。”
end select
getattributes = str
else
getattributes = -1
end if
end function
最后一次访问/最后一次修改时间
response.write showfileaccessinfo(“g: oft\delphi\my_pro\复件 代码库.exe”)
function showfileaccessinfo(filename,infotype)
//功能:显示文件创建时信息
//形参:文件名,信息类别
// 1 —–创建时间
// 2 —–上次访问时间
// 3 —–上次修改时间
// 4 —–文件路径
// 5 —–文件名称
// 6 —–文件类型
// 7 —–文件大小
// 8 —–父目录
// 9 —–根目录
//返回值:成功为文件创建时信息,失败:-1
//
dim f, s
if reportfilestatus(filename) = 1 then
set f = fso.getfile(filename)
select case infotype
case 1 s = f.datecreated // 1 —–
创建时间
case 2 s = f.datelastaccessed // 2 —–上次访问
时间
case 3 s = f.datelastmodified // 3 —–上次修改
时间
case 4 s = f.path // 4
—–文件路径
case 5 s = f.name // 5
—–文件名称
case 6 s = f.type // 6
—–文件类型
case 7 s = f.size // 7
—–文件大小
case 8 s = f.parentfolder // 8 —–
父目录
case 9 s = f.rootfolder // 8 —–
根目录
end select
showfileaccessinfo = s
else
showfileaccessinfo = -1
end if
end function
写文本文件
function writetxtfile(filename,textstr,writeorappendtype)
const forreading = 1, forwriting = 2 , forappending = 8
dim f, m
select case writeorappendtype
case 1: 文件进行写操作
set f = fso.opentextfile(filename, forwriting, true)
f.write textstr
f.close
if reportfilestatus(filename) = 1 then
writetxtfile = 1
else
writetxtfile = -1
end if
case 2: 文件末尾进行写操作
if reportfilestatus(filename) = 1 then
set f = fso.opentextfile(filename, forappending)
f.write textstr
f.close
writetxtfile = 1
else
writetxtfile = -1
end if
end select
end function
读文本文件
function readtxtfile(filename)
const forreading = 1, forwriting = 2
dim f, m
if reportfilestatus(filename) = 1 then
set f = fso.opentextfile(filename, forreading)
m = f.readline
m = f.readall
f.skipline
readtxtfile = m
f.close
else
readtxtfile = -1
end if
end function
建立文本文件
//==================================目录操作==================================
取目录大小
function getfoldersize(foldername)
//功能:取目录大小
//形参:目录名
//返回值:成功为目录大小,失败为-1
//
dim f
if reportfolderstatus(foldername) = 1 then
set f = fso.getfolder(foldername)
getfoldersize = f.size
else
getfoldersize = -1
end if
end function
创建的文件夹
function createfolderdemo(foldername)
//功能:创建的文件夹
//形参:目录名
//返回值:成功为1,失败为-1
//
dim f
if reportfolderstatus(folderspec) = 1 then
createfolderdemo = -1
else
set f = fso.createfolder(foldername)
createfolderdemo = 1
end if
end function
!!!
目录删除
function deleteafolder(folderspec)
//功能:目录删除
//形参:目录名
//返回值:成功为1,失败为-1
//
response.write folderspec
if reportfolderstatus(folderspec) = 1 then
fso.deletefolder (folderspec)
deleteafolder = 1
else
deleteafolder = -1
end if
end function
显示目录列表
function showfolderlist(folderspec)
//功能:目录存在时显示此目录下的所有子目录
//形参:目录名
//返回值:成功为子目录列表,失败为-1
//
dim f, f1, fc, s
if reportfolderstatus(folderspec) = 1 then
set f = fso.getfolder(folderspec)
set fc = f.subfolders
for each f1 in fc
s = s & f1.name
s = s & “|”
next
showfolderlist = s
else
showfolderlist = -1
end if
end function
!!!!
目录复制
function copyafolder(sourcefolder,destinationfolder)
//功能:源目录存在时,才能对目录进行复制,目的目录无影响
//形参:源目录,目的目录
//返回值:成功为1,失败为-1
//
dim myfolder
if reportfolderstatus(sourcefolder) = 1 and reportfolderstatus
(destinationfolder) = -1 then
set myfolder = fso.getfolder(sourcefolder)
fso.copyfolder sourcefolder,destinationfolder
copyafolder = 1
else
copyafolder = -1
end if
end function
目录进行移动
function moveafolder(sourcepath,destinationpath)
//功能:源目录存在时目的目录不存在时才能对目录进行移动
//形参:源目录,目的目录
//返回值:成功为1,失败为-1
//
if reportfolderstatus(sourcepath)=1 and reportfolderstatus(destinationpath)=0
then
fso.movefolder sourcepath, destinationpath
moveafolder = 1
else
moveafolder = -1
end if
end function
判断目录是否存在
response.write reportfolderstatus(“g: oft\delphi\my_pro\”)
function reportfolderstatus(fldr)
//功能:判断目录是否存在
//形参:目录
//返回值:成功为1,失败为-1
//
dim msg
msg = -1
if (fso.folderexists(fldr)) then
msg = 1
else
msg = -1
end if
reportfolderstatus = msg
end function
目录创建时信息
function showfolderaccessinfo(foldername,infotype)
//功能:显示目录创建时信息
//形参:目录名,信息类别
// 1 —–创建时间
// 2 —–上次访问时间
// 3 —–上次修改时间
// 4 —–目录路径
// 5 —–目录名称
// 6 —–目录类型
// 7 —–目录大小
// 8 —–父目录
// 9 —–根目录
//返回值:成功为目录创建时信息,失败:-1
//
dim f, s
if reportfolderstatus(foldername) = 1 then
set f = fso.getfolder(foldername)
select case infotype
case 1 s = f.datecreated // 1 —–
创建时间
case 2 s = f.datelastaccessed // 2 —–上次访问
时间
case 3 s = f.datelastmodified // 3 —–上次修改
时间
case 4 s = f.path // 4
—–文件路径
case 5 s = f.name // 5
—–文件名称
case 6 s = f.type // 6
—–文件类型
case 7 s = f.size // 7
—–文件大小
case 8 s = f.parentfolder // 8 —–
父目录
case 9 s = f.rootfolder // 9 —–
根目录
end select
showfolderaccessinfo = s
else
showfolderaccessinfo = -1
end if
end function
function displayleveldepth(pathspec)
dim f, n ,path
set f = fso.getfolder(pathspec)
if f.isrootfolder then
displayleveldepth =”指定的文件夹是根文件夹。”&rootfolder
else
do until f.isrootfolder
path = path & f.name &”<br>”
set f = f.parentfolder
n = n + 1
loop
displayleveldepth =”指定的文件夹是嵌套级为 ” & n & ” 的文件夹。<br>”&
path
end if
end function
//==================================磁盘操作==================================
驱动器是否存在?
response.write reportdrivestatus(“c:\”)
function reportdrivestatus(drv)
//功能:判断磁盘是否存在
//形参:磁盘
//返回值:成功为1,失败为-1
//
dim msg
msg = -1
if fso.driveexists(drv) then
msg = 1
else
msg = -1
end if
reportdrivestatus = msg
end function
——–可用的返回类型包括 fat、ntfs 和 cdfs。
response.write showfilesystemtype(“c:\”)
function showfilesystemtype(drvspec)
//功能:磁盘类型
//形参:磁盘名
//返回值:成功为类型:fat、ntfs 和 cdfs,失败:-1
//
dim d
if reportdrivestatus(drvspec) = 1 then
set d = fso. getdrive(drvspec)
showfilesystemtype = d.filesystem
else
showfilesystemtype = -1
end if
end function
end class
%>