㈠ asp.net中怎样复制文件
1)引用命名空间
using System.IO;
2)复制文件
File.Copy(Server.MapPath("被复制的文件相对路径"), Server.MapPath("目的位置相对路径"), false);
注意:第三个参数若专为true,那么目标位置存属在同名文件将被覆盖.
不知道对不对,呵呵
㈡ asp如何循环读取指定文件夹文件夹中的文件名
刚写完代码问题关闭了, 没把我晕死.
你看一看吧 不懂可以问我.
========================================================================
没有时间把整站代码都写给你
大概说下思路吧
1,遍历文件夹取文件对象值,添加在数据库中(先建好表方便一些),然后操作Drive对象,取数据库值取表格值或输入值都可以,假设要复制文件夹中所有文件的话就直接在遍历循环中建FSO对象,不过代码复杂一点.
祝你成功.
给你一些主要functions和思路,你会发现其实点破了就很简单:
1.
function bianli(path)
Set fso = Server.CreateObject("Scripting.FileSystemObject")
on error resume next
Set objFolder=fso.GetFolder(server.MapPath(path))
Set objFiles=objFolder.Files
'循环输出文件夹path下的文件的文件名
For each objFile in objFiles '取相关值
Response.Write "Name: " & objFile.Name & " "
Response.Write "ShortName: " & objFile.ShortName & " "
Response.Write "Size: " & objFile.Size & " bytes "
Response.Write "Type: " & objFile.Type & "<BR>"
Response.Write "Path: " & objFile.Path & " "
Response.Write "ShortPath: " & objFile.ShortPath & "<BR>"
Response.Write "Created: " & objFile.DateCreated & " "
Response.Write "LastModified: " & objFile.DateLastModified & "<P>"
Next
Set objFolder=nothing
Set fso=nothing '释放对象
end function
下面的建表写表就不用我说了吧?
==========================================================================
2.文件复制操作'之讲了复制,下面有详细关于File对象的讲解,希望触类旁通
Sub backupdata()
Filepath=request.form("Filepath")
Filepath=server.mappath(Filepath)
bkfolder=request.form("bkfolder")
bkfilename=request.form("bkfilename")
Set Fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(Filepath) then
If CheckDir(bkfolder) = True Then
fso.file Filepath,bkfolder& "\"& bkfilename
else
MakeNewsDir bkfolder
fso.file Filepath,bkfolder& "\"& bkfilename
end if
response.write "操作成功,您备份的数据路径为<br>" &bkfolder& "\"& bkfilename
Else
response.write "找不到您所需要备份的文件。"
End if
end sub
Driver对象的RootFolder属性返回一个Folder对象,通过该对象可访问这个驱动器内的所有的内容。可以使用这个Folder对象的属性和方法遍历驱动器上的目录,并得到该文件夹和其他文件夹的属性。
Copy(destination,overwrite)
将这个文件复制到destination指定的文件夹。如果destination的末尾是路径分隔符(‘\’),那么认为destination是放置拷贝文件的文件夹。否则认为destination是要创建的新文件的路径和名字。如果目标文件已经存在且overwrite参数设置为False,将产生错误,缺省的overwrite参数是True
Delete(force)
删除这个文件。如果可选的force参数设置为True,即使文件具有只读属性也会被删除。缺省的force是False
Move(destination)
将文件移动到destination指定的文件夹。如果destination的末尾是路径分隔符(‘\’),那么认为destination是一文件夹。否则认为destination是一个新的文件的路径和名字。如果目标文件夹已经存在,则出错
CreateTextFile
(filename,overwrite,unicode)
用指定的文件名创建一个新的文本文件,并且返回一个相应的TextStream对象。如果可选的overwrite参数设置为True,将覆盖任何已有的同名文件。缺省的overwrite参数是False。如果可选的unicode参数设置为True,文件的内容将存储为unicode文本。缺省的unicode是False
OpenAsTextStream
(iomode,format)
打开指定文件并且返回一个TextStream对象,用于文件的读、写或追加。iomode参数指定了要求的访问类型,允许值是ForReading(1) (缺省值)、ForWrite(2)、ForAppending(8)。format参数说明了读、写文件的数据格式。允许值是TristateFalse(0)(缺省),说明用ASCII数据格式;TristateTrue(-1)说明用Unicode数据格式;TristateUseDefault(-2)说明使用系统缺省格式
不是为了多少分 主要能帮到你就可以