2014-02-20 72 views
-1

我正在尋找一個程序來打開一個文件,保存後,程序會將它保存到一個新的文件夾中,保持原來的文件不變。將文件保存到新文件夾中?

但是,我試過的代碼都沒有工作。

如何創建一個新的文件夾進入加載文件的FilePath?

我該如何保存到該文件夾​​?

我嘗試這樣做,得到了錯誤。「假未找到或無法訪問」

Private Sub SaveChangesToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveChangesToolStripMenuItem1.Click newFilePath = FilePath + "\" + newFolderName + "Folder" Try Dim Writer As New PackageIO.Writer(newFilePath = orgFilePath + "\" + newFolderName, "Folder 1", PackageIO.Endian.Big) System.IO.Directory.CreateDirectory(newFilePath)

我在這裏嘗試這樣的代碼,它似乎是最接近的工作,但他說文件路徑無效;我假設,因爲它包括他們選擇的文件,而不僅僅是涉及的文件夾。

Private Sub SaveChangesToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveChangesToolStripMenuItem1.Click newFilePath = FilePath + "\" + newFolderName + "Folder" Try Dim Writer As New PackageIO.Writer(newFilePath, PackageIO.Endian.Big) System.IO.Directory.CreateDirectory(newFilePath)

+1

讓我們看看你已經嘗試了代碼。 –

+0

更具體請,什麼樣的文件?文本?字? Excel中?你有什麼試過btw? – Rex

回答

0

試試沿着這些線路:

Dim orgFilePath as String 
Dim newFolderName as String 
Dim newFilePath as String 

'you will need to set the path of the original file and give a name for the new folder 
newFilePath = orgFilePath + "\" + newFolderName 

'creates new directory (folder) 
System.IO.Directory.CreateDirectory(newFilePath) 

'then put the code to save your file to the newFilePath variable 

希望幫助

+0

我嘗試這樣做,得到了錯誤。「假未找到或無法訪問」 '私人小組SaveChangesToolStripMenuItem1_Click(BYVAL發件人爲System.Object的,BYVALË作爲System.EventArgs)把手SaveChangesToolStripMenuItem1.Click 嘗試 昏暗的作家作爲新的PackageIO.Writer(newFilePath = orgFilePath +「\」+ newFolderName,「Folder 1」,PackageIO.Endian.Big) System.IO.Directory.CreateDirectory(newFilePath)' –

+0

我在這裏試過這段代碼,它似乎是離工作最近,但表示文件路徑無效;我假設,因爲它包括他們選擇的文件,而不僅僅是涉及的文件夾。 '私人小組SaveChangesToolStripMenuItem1_Click(BYVAL發件人爲System.Object的,BYVALË作爲System.EventArgs)把手SaveChangesToolStripMenuItem1.Click newFilePath = FILEPATH + 「\」 + newFolderName + 「文件夾」 嘗試 昏暗作家作爲新PackageIO.Writer(newFilePath ,PackageIO.Endian.Big) System.IO.Directory.CreateDirectory(newFilePath)' –

相關問題