利用FSO的创建文件夹,文件,删除文件重命名等等

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

利用FSO的创建文件夹,文件,删除文件重命名等等
fso的创建文件夹,文件,删除文件,重命名等等
千万要支持下哦!不明白的可电话联系我134********
<%
'/doc/3312896609.html,
Function AutoCreateFolder(strPath) ' As Boolean
On Error Resume Next
Dim astrPath, ulngPath, i, strTmpPath
Dim objFSO
If InStr(strPath, "\") <=0 Or InStr(strPath, ":") <= 0 Then
AutoCreateFolder = False
Exit Function
End If
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strPath) Then
AutoCreateFolder = True
Exit Function
End If
astrPath = Split(strPath, "\")
ulngPath = UBound(astrPath)
strTmpPath = ""
For i = 0 To ulngPath
strTmpPath = strTmpPath & astrPath(i) & "\"
If Not objFSO.FolderExists(strTmpPath) Then
' 创建
objFSO.CreateFolder(strTmpPath)
End If
Next
Set objFSO = Nothing
If Err = 0 Then
AutoCreateFolder = True
Else
AutoCreateFolder = False
End If
End Function
%>
papername=session("paperName")
username=session("user_name")
'自动创建文件夹
pathsub1=papername
MyPath = server.mappath(pathsub1)
AutoCreateFolder(MyPath)
====================================== =============================
'建立文件
filename = year(date()) & month(date()) & day(date()) & hour(time()) & minute(time()) &
second(time()) & ".txt"
Set fso = Server.createobject("scripting.filesystemobject")
thepath = Server.mappath(filename)
Set thefile = fso.createTextfile(thepath)
thefile.writeline "新建立文件"
thefile.close
Set fso = Nothing
'删除文件
Sub DelFile(filename)
Dim fo,filenamestr
Set fo = Server.Createobject("Scripting.FileSystemObject") filenamestr = Server.MapPath(filename)
If fo.FileExists(filenamestr) Then fo.DeleteFile filenamestr
Set fo = Nothing
End Sub
重命名
<%
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile server.mappath("tupian.jpg"),server.mappath("图片.jpg")
Set fso=Nothing
%>
方法二:
<%
Dim fso,f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(server.mappath("tupian.jpg"))
/doc/3312896609.html,="图片.jpg"
Set f=Nothing
Set fso=Nothing
%>
fso中判断文件夹是否存在
set fso = server.createobject("ing.filesystemobject")
if fso.FolderExists(server.mappath("../folderName"))=false then
REsponse.write("此文件夹不存在")
end if
fso中判断文件是否存在
set fso = server.createobject("ing.filesystemobject")
if
fso.fileexists(server.mappath("../folderName/fileName.htm")) = true then
Response.write("文件存在")
end if
一,fso.GetFile
提取文件相应的 File 对象
1,getfile.asp
<%
whichfile=Server.MapPath("cnbruce.tx
t")
Set fso = CreateObject("s cripting.FileSystemObject")
Set f1 = fso.CreateTextFile(whichfile,true)
f1.Write ("This is a test.My Name is cnbruce.")
f1.Close
Set f2 = fso.GetFile(whichfile)
s = "文件名称:" & /doc/3312896609.html, & "
"
s = s & "文件短路径名:" & f2.shortPath & "
"
s = s & "文件物理地址:" & f2.Path & "
"
s = s & "文件属性:" & f2.Attributes & "
"
s = s & "文件大小: " & f2.size & "
"
s = s & "文件类型: " & f2.type & "
"
s = s & "文件创建时间: " & f2.DateCreated & "
"
s = s & "最近访问时间: " & f2.DateLastAccessed & "
"
s = s & "最近修改时间: " & f2.DateLastModified
response.write(s)
%>
其效果正如右键某文件,看到的具体属性信息。

其中Attributes返回的数值“32”表示:(Archive)上次备份后已更改的文件。

可读写。

其它值附录如下:
Normal 0 普通文件。

没有设置任何属性。

ReadOnly 1 只读文件。

可读写。

Hidden 2 隐藏文件。

可读写。

System 4 系统文件。

可读写。

Directory 16 文件夹或目录。

只读。

Archive 32 上次备份后已更改的文件。

可读写。

Alias 1024 链接或快捷方式。

只读。

Compressed 2048 压缩文件。

只读。

二,file.move
作用将指定的文件或文件夹从某位置移动到另一位置。

其实该方法仍然属于fso.GetFile后的一个应用。

2,movefile.asp
<%
whichfile=Server.MapPath("cnbruce.txt")
Set fso = CreateObject("s cripting.FileSystemObject")
Set f1 = fso.CreateTextFile(whichfile,true)
f1.Write ("This is a test.My Name is cnbruce.")
f1.Close
Set f2 = fso.GetFile(whichfile)
f2.Move "C:\"
%>
查看下有没有
简单的剪切粘贴的功能实现。

三,File.Copy
同样属于fso.GetFile后的一个应用。

就只是单纯地拷贝文件到某位置。

3,copyfile.asp
<%
whichfile=Server.MapPath("cnbruce.txt")
Set fso = CreateObject("s cripting.FileSystemObject")
Set f1 = fso.CreateTextFile(whichfile,true)
f1.Write ("This is a test.My Name is cnbruce.")
f1.Close
Set f2 = fso.GetFile(whichfile)
f2.Copy "D:\"
%>
查看下有没有
和本ASP页面同在目录下的cnbruce.txt文件依然存在。

四,file.Delete
很显然,就是直接删除文件了。

4,delfile.asp
<%
whichfile=Server.MapPath("cnbruce.txt")
Set fso = CreateObject("s cripting.FileSystemObject") Set f1 = fso.CreateTextFile(whichfile,true)
f1.Write ("This is a test.My Name is cnbruce.")
f1.Close
Set f2 = fso.GetFile(whichfile)
f2.move "d:\"
Set f3 = fso.GetFile("d:\cnbruce.txt")
f3.delete
%>
查看下是没有该文件的。

相关文档
最新文档