VB.NET拷贝整个目录下所有子目录及文件的实例代码
程序员文章站
2024-02-29 13:01:40
复制代码 代码如下: public sub copyderictory(byval directorysrc as directoryinfo, byval di...
复制代码 代码如下:
public sub copyderictory(byval directorysrc as directoryinfo, byval directorydes as directoryinfo)
dim strdirectorydespath as string = directorydes.fullname & "" & directorysrc.name
if not directory.exists(strdirectorydespath) then
directory.createdirectory(strdirectorydespath)
end if
dim f, fs() as fileinfo
fs = directorysrc.getfiles()
for each f in fs
file.copy(f.fullname, strdirectorydespath & "" & f.name, true)
next
dim dirsrc, dirs() as directoryinfo
dirs = directorysrc.getdirectories()
// 递归调用自身
for each dirsrc in dirs
dim dirdes as new directoryinfo(strdirectorydespath)
copyderictory(dirsrc, dirdes)
next
end sub
private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
copyderictory(new directoryinfo("c:documents and settingsusernamefavorites"), new directoryinfo("g: emp"))
end sub
上一篇: java IO 文件操作方法总结
下一篇: mybatis中的缓存问题解析