2010年7月16日 星期五

連線遠端分享的資料夾,進行資料管理

1. 加入Reference:Microsoft.VisualBasic

2.在Class的開頭設定 using FileIO Class

using Microsoft.VisualBasic.FileIO;

3.可使用之相關函式,舉例:

3.1 FileSystem.CreateDirectory("C:\Documents and Settings\All Users\Documents\NewDirectory");

3.2 FileSystem.CopyDirectory(sourceDirectoryName ,destinationDirectoryName)
FileSystem.CopyDirectory(sourceDirectoryName ,destinationDirectoryName ,overwrite)
FileSystem.CopyDirectory(sourceDirectoryName ,destinationDirectoryName ,showUI)
FileSystem.CopyDirectory(sourceDirectoryName ,destinationDirectoryName ,showUI ,onUserCancel)


3.3 ' Copy the file to a new location without overwriting existing file.
FileSystem.CopyFile( "C:\UserFiles\TestFiles\testFile.txt", "C:\UserFiles\TestFiles2\testFile.txt")

' Copy the file to a new folder, overwriting existing file.
FileSystem.CopyFile( "C:\UserFiles\TestFiles\testFile.txt", "C:\UserFiles\TestFiles2\testFile.txt", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)

' Copy the file to a new folder and rename it.
FileSystem.CopyFile( "C:\UserFiles\TestFiles\testFile.txt", "C:\UserFiles\TestFiles2\NewFile.txt", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)


3.4 FileSystem.DeleteFile("C:\test.txt")

4. 如果是連結遠端的一個資料夾,路徑名稱設定方式為 @"\\ip\SharerdDirName"

例如:@"\\10.56.70.168\UserFiles"

微軟MSDN FileSystem Class

沒有留言:

張貼留言