对象保存区域 [英] Object Save Zone
问题描述
如何在文件中保存对象?
留出时间反转。
嗨Abdu,
您的问题很短,所以不确定这是否合适,但此代码会复制文件夹及相关文件/对象。
私有共享子DirectoryCopy(ByVal sourceDirName As String,ByVal destDirName As String)
        Dim dir As DirectoryInfo = New DirectoryInfo(sourceDirName)
Dim dirs As DirectoryInfo()= dir.GetDirectories()
Dim subdir As DirectoryInfo
'如果源目录不存在,则抛出异常。
如果不是dir.Exists则为
"          抛出新的DirectoryNotFoundException("源目录不存在或找不到:"+ sourceDirName)
 返回
结束如果
'如果目标目录不存在,请创建它。
如果不是Directory.Exists(destDirName)则为
Directory.CreateDirectory(destDirName)
结束如果
'获取要复制的目录的文件内容。
Dim files As FileInfo()= dir.GetFiles()
Dim file As FileInfo
对于每个文件在文件中
'创建文件新副本的路径。
Dim temppath As String = Path.Combine(destDirName,file.Name)
'复制文件。
file.CopyTo(temppath,True)
下一个文件
For Each subdir In dirs
'创建子目录。
Dim temppath As String = _
Path.Combine(destDirName,subdir.Name)
'复制子目录。
DirectoryCopy(subdir.FullName,temppath)
下一个子目录
结束子
我希望这会有所帮助: - )
跨度> 跨度> 跨度> 跨度> 跨度>
How I can save an object in a file?
Allow time to reverse.
Hi Abdu,
Your question was short, so not sure if this is appropriate but this code will copy a folder and associated files/objects therin.
Private Shared Sub DirectoryCopy(ByVal sourceDirName As String, ByVal destDirName As String)
Dim dir As DirectoryInfo = New DirectoryInfo(sourceDirName)
Dim dirs As DirectoryInfo() = dir.GetDirectories()
Dim subdir As DirectoryInfo' If the source directory does not exist, throw an exception.
If Not dir.Exists Then
' Throw New DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName)
Return
End If' If the destination directory does not exist, create it.
If Not Directory.Exists(destDirName) Then
Directory.CreateDirectory(destDirName)
End If' Get the file contents of the directory to copy.
Dim files As FileInfo() = dir.GetFiles()
Dim file As FileInfoFor Each file In files
' Create the path to the new copy of the file.
Dim temppath As String = Path.Combine(destDirName, file.Name)' Copy the file.
file.CopyTo(temppath, True)
Next fileFor Each subdir In dirs
' Create the subdirectory.
Dim temppath As String = _
Path.Combine(destDirName, subdir.Name)' Copy the subdirectories.
DirectoryCopy(subdir.FullName, temppath)
Next subdir
End SubI hope this helps :-)
这篇关于对象保存区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!