asp 服务器文件重命名,asp读取指定目录下的文件名

bianli(Server.MapPath(“/”)+”\pic”)

InStrRev(“abcd.jpg”, “.”) 计算出abcd.jpg中第一次出现.所在的位置是第几个字符=5

mid(“abcd.jpg”,1,4) 取前四位abcd

mid(“abcd.jpg”,5) 从五位往后取(包括第五位) .jpg

取前缀abc

FullPath = “abc.jpg”

f = mid(FullPath,1,InStrRev(FullPath, “.”)-1)

Response.Write f

娶后缀jpg

FullPath = “abc.jpg”

f = mid(FullPath,InStrRev(FullPath, “.”)+1)

Response.Write f

Set MyFileObject=Server.CreateObject(“Scripting.FileSystemObject”)’创建一个Folder对象

foldername=server.mappath(“./”)

Set MyFolder=MyFileObject.GetFolder(foldername)

i=0’循环显示其中文件夹

response.write “显示文件夹:”

For Each thing in MyFolder.subfolders

Response.Write(“
”&thing)

i=i+1

Next

response.write “
共有”&i&”个文件夹”

response.write “

显示文件名”‘循环显示其中文件

i=0

For Each thing in MyFolder.Files

Response.Write(“
”&thing)

i=i+1

Next

response.write “
共有”&i&”个文件”

%>

Set MyFileObject=Server.CreateObject(“Scripting.FileSystemObject”)’创建一个Folder对象

Set MyFolder=MyFileObject.GetFolder(server.mappath(“.”))

For Each thing in MyFolder.Files

thing=mid(thing,InStrRev(thing, “\”)+1)

f = mid(thing,InStrRev(thing, “.”)+1)

Set Reg = New RegExp

Reg.Pattern=”test”

Set Matche=Reg.Execute(thing) ‘正则匹配Matches.Count<1表示不选;Matches.Count>1 就是匹配到选中

Reg.Pattern=”lin”

Set Matches=Reg.Execute(thing)

IF Matches.Count<1 And Matche.Count<1 And f=”asp” And thing<>”lin.asp” And thing<>”tpl.asp” And thing<>”tiao.asp” And thing<>”master.asp” And thing<>”delete.asp” Then

Response.Write thing

Response.Write(“
”)

End If

Next

%>

————————————————————————————————————————————

生用的遍历文件:

Response.Expires = 0

function bianli(path)

dim fso ‘fso对象

dim objFolder ‘文件夹对象

dim objFiles ‘文件集合

dim objFile ‘文件对象

set fso=server.CreateObject(“scripting.filesystemobject”)

on error resume next

set objFolder=fso.GetFolder(path)’创建文件夹对象

set objSubFolders=objFolder.Subfolders’

for each objSubFolder in objSubFolders

nowpath=path + objSubFolder.name + “\”

Response.Write nowpath

set objFiles=objFolder.Files

for each objFile in objFiles

Response.Write (objFile.name)

Response.Write “

Next

bianli(nowpath) ‘调用递归

next

set objFolder=nothing

set objSubFolders=nothing

set fso=nothing

end function

%>

bianli(Server.MapPath(“/”) + “/new”) ‘调用bianli()函数,这里是遍历当前目录下的new文件夹

%>

—————————————————————————————————-

Set fso=Server.CreateObject(“Scripting.FileSystemObject”)’创建一个Folder对象

fpath=”.”‘Request.form(“fpath”)

set objfolder=fso.getfolder(server.mappath(fpath))

for each objsubfolder in objfolder.subfolders

Response.write “子文件夹名称:” & objsubfolder.name & “

next

Response.write “

for each objfile in objfolder.files

Response.write objfile.name & “

exitname=fso.GetExtensionName(objfile.name)’文件后缀也可以用这获取f = mid(thing,InStrRev(thing, “.”)+1)’取asp后缀的文件 f=”asp”

response.Write exitname & “

next

set objfolder=nothing

%>

—————————————————————————————–

Sub GetFolderObj(FD_getfolder)

For each SFolder in FD_getfolder.subfolders

call GetFileObj(SFolder)

call GetFolderObj(SFolder)

Next

End Sub

Sub GetFileObj(FD_getfile)

WritePath(FD_getfile)

For each MF in FD_getfile.files

call WriteFileMes(MF)

Next

End Sub

Sub WriteFileMes(MyFileObj)

%>

End Sub

Sub WritePath(FDObj)

%>

下面的文件有:

End Sub

Sub main()

Set fso =Server.CreateObject(“Scripting.FileSystemObject”)

Set PFD=fso.getfolder(server.MapPath(“.”))

Response.Write(“

call GetFileObj(PFD)

call GetFolderObj(PFD)

Response.Write(“

”)

End sub

%>

所有文件

td {

font-family: Arial, Helvetica, sans-serif;

font-size: 12px;

}

–>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ASP是一种服务器端脚本语言,用于开发动态的Web应用程序。它具有强大的文件上传功能,可以实现将文件上传到服务器的功能。 要实现文件上传功能,首先需要在ASP页面中添加一个文件上传表单。表单中需要包含一个<input type="file">类型的input标签,用于选择要上传的文件。在表单的action属性中指定服务器端处理文件上传的ASP页面。当用户点击提交按钮时,选择的文件会被自动上传到服务器。 在接收文件的ASP页面中,需要使用ASP内置的对象和方法来处理文件上传。可以使用Request对象的Files集合来获取上传的文件。例如,可以使用Request.Files("file")来获取名为file的文件。 接下来,可以使用FileSystemObject对象来处理上传的文件。通过创建一个FileSystemObject对象,可以使用其方法和属性来管理文件系统。可以使用FileSystemObject对象的MoveFile方法将上传的文件移动到指定服务器文件夹中,也可以使用CopyFile方法将文件复制到指定目录。 需要注意的是,服务器端必须对上传的文件进行安全检查。可以通过检查文件的类型、文件大小等属性来确保上传的文件是合法和安全的。可以使用ASP的内置对象来获取文件的类型和大小等信息。 总结起来,ASP上传文件到服务器的过程包括创建文件上传表单、获取上传的文件、使用FileSystemObject对象处理文件,并对上传的文件进行安全检查。通过这些步骤,就可以实现在ASP中将文件上传到服务器的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值