LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

ASP之FSO函数大全

admin
2010年7月22日 21:58 本文热度 5245

<%
'asp中一些fso方面的函数


'//==================================文件操作==================================


'取文件大小
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:\soft\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:\soft\delphi\my_pro\代码库.exe")
'response.write showdatecreated("g:\soft\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:\soft\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:\soft\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(foldername) = 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:\soft\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 &"
"

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
%>


该文章在 2010/7/22 21:58:40 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved