一个用FSO操作的对像,可以移除文件,查看文件夹下的文件等等。。。
<%
Sub ManipFiles'移除单个文件或拷贝单个文件。
Dim fso, f1, f2, s
Set fso = CreateObject("Scripting.FileSystemObject")
' Set f1 = fso.CreateTextFile("F:/fi.txt", True)
'Response.Write "Writing file <br>"
' 写入一行。
'f1.Write ("This is a test.")
' 关闭写入到的文件。
'f1.Close
'response.End()
'Response.Write "Moving file to F:/filename<br>"
' 获取到 C: 根目录中文件的句柄。
Set f2 = fso.GetFile("F:/filename/2006-4/1.jpg")
' 将文件移到 tmp 目录。
f2.Move ("F:/filename.jpg")'剪切文件并更改文件名
Response.Write "Copying file to F:/filename<br>"
' 将文件复制到 temp。
'f2.Copy ("F:/filename/file.txt")
'Response.Write "Deleting files <br>"
' 获得文件当前位置的句柄。
'Set f2 = fso.GetFile("F:/filename.txt")
'Set f3 = fso.GetFile("F:/filename/2006-4/testfile.txt")
' 删除文件。
'f2.Delete
'f3.Delete
Response.Write "All done!"
End Sub
'/************移除多个文件,或是同扩展名的文件****************/
Sub MoveAFile(Drivespec,ParentUrlPath,f_id)
Dim fso
ParentDrivePath=server.MapPath(ParentUrlPath)'固定目录的物理路径
'IntentionFolder="pic"'固定目录的物理路径的下一级路径
IntentionDriveFolder=ParentDrivePath&""&IntentionFolder&""'全部目的物理路径文件夹
Randomize
RandomFigure = CStr(Int((99999 * Rnd) + 1))
FileName=Year(Now())&Right("0"&Month(Now()),2)&Right("0"&Day(Now()),2)&Right("0"&Hour(Now()),2)&Right("0"&Minute(Now()),2)&Right("0"&Second(Now()),2)&RandomFigure
Set fso = CreateObject("Scripting.FileSystemObject")
PicFileExt=fso.GetExtensionName(Drivespec)'获取扩展名
IntentionPath=IntentionDriveFolder&FileName&"."&PicFileExt'全部目的物理路径文件夹下的文件名
FileName=FileName&"."&PicFileExt'文件名加上扩展名组成了完整的文件全称
'response.Write(ParentUrlPath)
'response.End()
if fso.FileExists(Drivespec) then'文件是否存在
fso.MoveFile Drivespec,IntentionPath
UpdatePicPath ParentUrlPath&IntentionFolder&"/"&FileName,f_id'调用更新函数
else
response.Write(Drivespec&"文件不存在")
end if
End Sub
'/*******遍历文件夹中的文件*********/
Function ShowFileList(folderspec)'遍历文件夹的文件
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & "<BR>"
Next
ShowFileList = s
End Function
'/***************遍历文件夹中的文件夹*************/
Function ShowFolderList(folderspec)
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.SubFolders
For Each f1 in fc
s = s & f1.name
s = s & "<BR>"
Next
ShowFolderList = s
End Function
'/*********更新图片路径***********/
Sub UpdatePicPath(PicPath,f_id)
conn.execute("update tablename set pic='"&PicPath&"' where f_id="&f_id)
end Sub
'/**********更新字段介绍里的截图片路径****************/
Sub UpdatePicPath_intro(intro,f_id)
conn.execute("update tablename set intro='"&intro&"' where f_id="&f_id)
end Sub
'/**********提出图片代码************************/
Function GetImagesInContent(strContent)
Set re=new RegExp
re.IgnoreCase =True
re.Global=false
MaxLoopCount = 5
s = strContent
strImageList = ""
LoopCount=0
re.Pattern = "(^[sS]*)<IMG.*src=""([^""]*)""([sS]*)"
Test=re.Test(s)
If Test Then
Do While Test
imgPath = re.Replace(s,"$2")
strImageList = strImageList & imgPath
s=re.Replace(s,"$1")
Test=re.Test(s)
LoopCount=LoopCount+1
If Test Then
strImageList = strImageList & "|"
End If
If LoopCount>20 Then Exit Do
Loop
End If
Set re = Nothing
'Set zk = Nothing
GetImagesInContent = strImageList
End Function
'/************拷贝文件********************/
Sub CopyFile(Drivespec,ParentUrlPath,f_id)
Dim fso
ParentDrivePath=server.MapPath(ParentUrlPath)'固定目录的物理路径
IntentionFolder="2006-4"'固定目录的物理路径的下一级路径
IntentionDriveFolder=ParentDrivePath&""&IntentionFolder&""'全部目的物理路径文件夹
Randomize
RandomFigure = CStr(Int((99999 * Rnd) + 1))
FileName=Year(Now())&Right("0"&Month(Now()),2)&Right("0"&Day(Now()),2)&Right("0"&Hour(Now()),2)&Right("0"&Minute(Now()),2)&Right("0"&Second(Now()),2)&RandomFigure
Set fso = CreateObject("Scripting.FileSystemObject")
PicFileExt=fso.GetExtensionName(Drivespec)'获取扩展名
IntentionPath=IntentionDriveFolder&FileName&"."&PicFileExt'全部目的物理路径文件夹下的文件名
FileName=FileName&"."&PicFileExt'文件名加上扩展名组成了完整的文件全称
'response.Write(ParentUrlPath)
'response.End()
if fso.FileExists(Drivespec) then'文件是否存在
fso.CopyFile Drivespec,IntentionPath
UpdatePicPath ParentUrlPath&IntentionFolder&"/"&FileName,f_id'调用更新函数
else
response.Write(Drivespec&"游戏小图片文件不存在")
end if
End Sub
'/**********拷贝介绍里的截图片文件的路径*******************/
Function CutCopyFile(Drivespec,ParentUrlPath,PicUrlPath,IntroStr,f_id)
Dim fso
ParentDrivePath=server.MapPath(ParentUrlPath)'固定目录的物理路径
IntentionFolder="pic"'固定目录的物理路径的下一级路径
IntentionDriveFolder=ParentDrivePath&""&IntentionFolder&""'全部目的物理路径文件夹
Randomize
RandomFigure = CStr(Int((99999 * Rnd) + 1))
FileName=Year(Now())&Right("0"&Month(Now()),2)&Right("0"&Day(Now()),2)&Right("0"&Hour(Now()),2)&Right("0"&Minute(Now()),2)&Right("0"&Second(Now()),2)&RandomFigure
Set fso = CreateObject("Scripting.FileSystemObject")
PicFileExt=fso.GetExtensionName(Drivespec)'获取扩展名
IntentionPath=IntentionDriveFolder&FileName&"."&PicFileExt'全部目的物理路径文件夹下的文件名
FileName=FileName&"."&PicFileExt'文件名加上扩展名组成了完整的文件全称
'response.Write(ParentUrlPath)
'response.End()
if fso.FileExists(Drivespec) then'文件是否存在
fso.CopyFile Drivespec,IntentionPath'拷贝文件
IntroStr=replace(IntroStr,PicUrlPath,ParentUrlPath&IntentionFolder&"/"&FileName)'替换介绍里面的图片URL地址
'UpdatePicPath_intro ParentUrlPath&IntentionFolder&"/"&FileName,f_id'调用更新函数
else
response.Write(Drivespec&"游戏截图片文件不存在")
end if
CutCopyFile=IntroStr
End Function
set rs=server.CreateObject("ADODB.recordset")
sql="select top 3 * from tablename where f_id >4 and f_id<8"
rs.open sql,conn,1,3
do while not rs.eof
PicNameArr=split(rs("pic"),"/")'修改小图片
PicNameArrNum=ubound(PicNameArr)
PicName=PicNameArr(PicNameArrNum)
for i=0 to PicNameArrNum
if PicNameArr(i)="games" then
ParentUrlPath=left(rs("pic"),instr(rs("pic"),"games")+5)'获取URL的根地址,从games/的“/”分开的左边地址。
end if
next
if PicName<>"nophoto.gif" then
f_title_pic=replace(rs("pic"),"com//","com/")
'response.Write(f_title_pic)
PicDriveFolder=server.MapPath(f_title_pic)'物理路径
'response.Write(PicDriveFolder)
'response.End()
'CopyFile PicDriveFolder,ParentUrlPath,rs("f_id")'调用拷贝文件函数(传递参数)
end if
'/-----------------------
IntroStr=rs("f_intro")'修改介绍里的游戏截图片
' response.Write(IntroStr)
' response.End()
IntroPic=GetImagesInContent(IntroStr)
CutPicArr=split(IntroPic,"|")
for m=0 to ubound(CutPicArr)
PicUrlPath=CutPicArr(m)
CutParentUrlPath=left(PicUrlPath,instr(PicUrlPath,"/games/")+6)'获取URL的根地址,从/games/的“/”分开的左边地址。
CutPicDriveFolder=server.MapPath(PicUrlPath)'物理路径
introStr=CutCopyFile(CutPicDriveFolder,CutParentUrlPath,PicUrlPath,IntroStr,rs("f_id"))
next
UpdatePicPath_intro introStr,rs("f_id")
' IntroStr=rs("f_intro")'修改介绍里的游戏截图片
'
' IntroPic=GetImagesInContent(IntroStr)
' CutPicArr=split(IntroPic,"|")
' for m=0 to ubound(CutPicArr)
' PicUrlPath=CutPicArr(m)
' IntroStr=replace(IntroStr,PicUrlPath,"/files/upfiles/games/2006-4/"&m+1&".jpg")
' next
' rs("f_intro")=IntroStr
' rs.update
' response.Write(rs("f_intro"))
''response.End()
'-----------------------/
rs.movenext
loop
%>
一个用FSO操作的对像
最新推荐文章于 2020-12-18 21:08:32 发布