Victor Charles
asked on
Help with exporting folder
Hi,
I'm using the code below to export an xml file, how do I modify it to export a folder which contains multiple xml files?
FolderBrowserDialog1.Selec tedPath = Application.StartupPath & "\LinkFiles"
Dim dlgResult As DialogResult
dlgResult = FolderBrowserDialog1.ShowD ialog()
If dlgResult = DialogResult.OK Then
System.IO.File.Copy(Applic ation.Star tupPath & "\LinkFiles\LinkFinal" & Trim(LoginForm1.username.T ext) & ".xml", _
FolderBrowserDialog1.Selec tedPath & "\LinkFinal" & Trim(LoginForm1.username.T ext) & ".xml")
End If
Thanks,
Victor
I'm using the code below to export an xml file, how do I modify it to export a folder which contains multiple xml files?
FolderBrowserDialog1.Selec
Dim dlgResult As DialogResult
dlgResult = FolderBrowserDialog1.ShowD
If dlgResult = DialogResult.OK Then
System.IO.File.Copy(Applic
FolderBrowserDialog1.Selec
End If
Thanks,
Victor
ASKER
Hi,
Thanks for the code. How do I check if the file exist before executing the code the export it?
Victor
Thanks for the code. How do I check if the file exist before executing the code the export it?
Victor
ASKER
Hi,
How do I modify the code to also import all files containing LinkFinal to my applications' LinkFiles sub folder?
If you prefer, I can post as a new question.
Thanks,
Victor
How do I modify the code to also import all files containing LinkFinal to my applications' LinkFiles sub folder?
If you prefer, I can post as a new question.
Thanks,
Victor
See your other question, "Help with over writing xml file," at https://www.experts-exchange.com/questions/28421332/Help-with-over-writing-xml-file.html for how to check if the destination file already exists.
All files in a single folder, or all files anywhere on your system? For all files in a single folder, just switch the source and destination folders. For all files anywhere on your system, you'll have to work recursively through the entire directory structure; see http://support.microsoft.com/kb/306666 for more details on how to do that.
All files in a single folder, or all files anywhere on your system? For all files in a single folder, just switch the source and destination folders. For all files anywhere on your system, you'll have to work recursively through the entire directory structure; see http://support.microsoft.com/kb/306666 for more details on how to do that.
ASKER
Hi,
I tried the code to export the files but received error message:
Access to the path '\LinkFinal.xml' is denied.
On line:
System.IO.File.Copy(oldFil e.FullName , FolderBrowserDialog1.Selec tedPath & "\" & oldFile.Name())
The folder is in the \Data\LinkFiles\ sub folder of the application.
Private Sub Button28_Click(sender As System.Object, e As System.EventArgs) Handles Button28.Click
Dim di As New System.IO.DirectoryInfo(Ap plication. StartupPat h & "\Data\LinkFiles")
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("LinkFinal*.xm l")
For Each oldFile As System.IO.FileInfo In FileInfoList
System.IO.File.Copy(oldFil e.FullName , FolderBrowserDialog1.Selec tedPath & "\" & oldFile.Name())
Next
End Sub
I tried the code to export the files but received error message:
Access to the path '\LinkFinal.xml' is denied.
On line:
System.IO.File.Copy(oldFil
The folder is in the \Data\LinkFiles\ sub folder of the application.
Private Sub Button28_Click(sender As System.Object, e As System.EventArgs) Handles Button28.Click
Dim di As New System.IO.DirectoryInfo(Ap
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("LinkFinal*.xm
For Each oldFile As System.IO.FileInfo In FileInfoList
System.IO.File.Copy(oldFil
Next
End Sub
That suggests that FolderBrowserDialog1.Selec tedPath is blank. In other words, you didn't select an output folder, or the name of the FolderBrowserDialog control that you're actually using doesn't match the one in this statement.
You should probably put a check in the procedure to make sure that FolderBrowserDialog1.Selec tedPath isn't blank.
You should probably put a check in the procedure to make sure that FolderBrowserDialog1.Selec
ASKER
Hi,
My Data\LinkFiles sub folder contains multiple LinkFinalXXX.xml files.
Below is my code, but I don't see the part that allows me to export the files from my "My Data\LinkFiles sub folder " to any folder I select.
Private Sub Button32_Click(sender As System.Object, e As System.EventArgs) Handles Button32.Click
Dim di As New System.IO.DirectoryInfo(Ap plication. StartupPat h & "\Data\LinkFiles")
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("LinkFinal*.xm l")
For Each oldFile As System.IO.FileInfo In FileInfoList
System.IO.File.Copy(oldFil e.FullName , FolderBrowserDialog1.Selec tedPath & "\" & oldFile.Name())
Next
End Sub
Thanks,
V.
My Data\LinkFiles sub folder contains multiple LinkFinalXXX.xml files.
Below is my code, but I don't see the part that allows me to export the files from my "My Data\LinkFiles sub folder " to any folder I select.
Private Sub Button32_Click(sender As System.Object, e As System.EventArgs) Handles Button32.Click
Dim di As New System.IO.DirectoryInfo(Ap
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("LinkFinal*.xm
For Each oldFile As System.IO.FileInfo In FileInfoList
System.IO.File.Copy(oldFil
Next
End Sub
Thanks,
V.
You select the output folder using the FolderBrowserDialog control, as we discussed in https://www.experts-exchange.com/questions/28420538/Help-with-choosing-path-to-save-file.html. Then the Copy statement copies files from the old location to the new. But if you never select a folder using the FBD control, there's no place to go.
ASKER
Thanks.
ASKER
Hi,
The code below works but how do I check if all the files from the source folder already exist in the target folder instead of just checking for LinkFinal & Trim(LoginForm1.username.T ext) & ".xml"?
FolderBrowserDialog1.Selec tedPath = Application.StartupPath & "\"
Dim dlgResult As DialogResult
dlgResult = FolderBrowserDialog1.ShowD ialog()
Dim NewFilename As String = FolderBrowserDialog1.Selec tedPath & "\LinkFinal" & Trim(LoginForm1.username.T ext) & ".xml"
If dlgResult = DialogResult.OK Then
If My.Computer.FileSystem.Fil eExists(Ne wFilename) Then
dlgResult = MessageBox.Show("File " & NewFilename & " already exist. Overwrite?", "File exists", _
MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Bu tton2)
If dlgResult = Windows.Forms.DialogResult .No Then
Return
End If
Dim di As New System.IO.DirectoryInfo(Ap plication. StartupPat h & "\Data\MasterFiles")
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("*.xml")
For Each oldFile As System.IO.FileInfo In FileInfoList
System.IO.File.Copy(oldFil e.FullName , FolderBrowserDialog1.Selec tedPath & "\" & oldFile.Name(), True)
Next
MsgBox("File succesfully exported")
Else
Dim di As New System.IO.DirectoryInfo(Ap plication. StartupPat h & "\Data\MasterFiles")
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("*.xml")
For Each oldFile As System.IO.FileInfo In FileInfoList
System.IO.File.Copy(oldFil e.FullName , FolderBrowserDialog1.Selec tedPath & "\" & oldFile.Name(), True)
Next
MsgBox("File succesfully exported")
End If
End If
Thanks,
Victor
The code below works but how do I check if all the files from the source folder already exist in the target folder instead of just checking for LinkFinal & Trim(LoginForm1.username.T
FolderBrowserDialog1.Selec
Dim dlgResult As DialogResult
dlgResult = FolderBrowserDialog1.ShowD
Dim NewFilename As String = FolderBrowserDialog1.Selec
If dlgResult = DialogResult.OK Then
If My.Computer.FileSystem.Fil
dlgResult = MessageBox.Show("File " & NewFilename & " already exist. Overwrite?", "File exists", _
MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Bu
If dlgResult = Windows.Forms.DialogResult
Return
End If
Dim di As New System.IO.DirectoryInfo(Ap
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("*.xml")
For Each oldFile As System.IO.FileInfo In FileInfoList
System.IO.File.Copy(oldFil
Next
MsgBox("File succesfully exported")
Else
Dim di As New System.IO.DirectoryInfo(Ap
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("*.xml")
For Each oldFile As System.IO.FileInfo In FileInfoList
System.IO.File.Copy(oldFil
Next
MsgBox("File succesfully exported")
End If
End If
Thanks,
Victor
ASKER
Regarding the Import function, all the files are in a single folder, can you please send me an example on how to switch the source and destination folders. I tried the code below bu the syntax is incorrect.
If My.Computer.FileSystem.Fil eExists(Ne wFilename) Then
dlgResult = MessageBox.Show("File " & NewFilename & " already exist. Overwrite?", "File exists", _
MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Bu tton2)
If dlgResult = Windows.Forms.DialogResult .No Then
Return
End If
Dim di As New System.IO.DirectoryInfo(Ap plication. StartupPat h & "\oldFile.Name()")
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("*.xml")
For Each oldFile As System.IO.FileInfo In FileInfoList
System.IO.File.Copy(oldFil e.FullName , FolderBrowserDialog1.Selec tedPath & \Data\MasterFilesTrue)
If My.Computer.FileSystem.Fil
dlgResult = MessageBox.Show("File " & NewFilename & " already exist. Overwrite?", "File exists", _
MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Bu
If dlgResult = Windows.Forms.DialogResult
Return
End If
Dim di As New System.IO.DirectoryInfo(Ap
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("*.xml")
For Each oldFile As System.IO.FileInfo In FileInfoList
System.IO.File.Copy(oldFil
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
I will try your code and get back to you.
Thanks,
Victor
I will try your code and get back to you.
Thanks,
Victor
ASKER
Hi again,
Just to clarify I'm trying to Export/Import all files in the folder selected instead of LinkFinal & Trim(LoginForm1.username.T ext) & ".xml".
I need to replace Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("LinkFinal*.xm l")
With
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles(*.xml")
Victor
Just to clarify I'm trying to Export/Import all files in the folder selected instead of LinkFinal & Trim(LoginForm1.username.T
I need to replace Dim FileInfoList As System.IO.FileInfo() = di.GetFiles("LinkFinal*.xm
With
Dim FileInfoList As System.IO.FileInfo() = di.GetFiles(*.xml")
Victor
ASKER
Ok, because filenames will vary, best approach maybe to warn users they will overwrite exit files and not include the code to check for exiting files.
Regarding your next-to-last message: Yes, if you want to get all the .xml files in the folder, you'd use "*.xml" rather than "LinkFinal*.xml". You know your own situation best, but it's often not necessary to warn people about overwriting an existing file if there's no reason that they would need the old file.
ASKER
Thank You.
Open in new window
Putting
Imports System.IO
at the top of the form code, of course, will save you having to retype System.IO every time.