Answered by:
Illegal Characters in path

Question
-
I have a CD that have some folders with illegal names like : <<setup>>, null ,etc
These folders contact some files that run properly. I want to run or copy them but I can`t.
I use System.Diagnostics.Process.Start(Path) and also FileCopy but it return an error :
Illegal characters in path. Is it possible to copy these files from these kinds of folders ?
Thank you for your helpThursday, May 22, 2008 11:59 AM
Answers
-
Mooshy wrote: Thank you for your post. But I think you didn`t notice to these things :
1- I have a folder with Illegal characters not a file.
2- These files are on CD, so I can`t change their names.
3- I want to get files names from this folder and copy them. Not run them !Thank you Cameron and Ale for your friendly help.
Hi Mooshy,
I think you firstly need to do this action in DOS command line manually or programmatically:
copy all files and subfolders (from that folder on CD containing illegal characters) to a legal folder
Xcopy SourceFolder DestinationFolder
Execute Dos command line in VB.NET:
Code SnippetPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Process.Start("Cmd.exe", "/C Xcopy SourceFolder DestinationFolder")
' /C parameter means exiting Cmd.exe after executing command
End Sub
Trackback: http://forums.microsoft.com:80/MSDN/ShowPost.aspx?PostID=2907940&SiteID=1
Then you can iterate/read all files and subfolders under a folder like this:
Code BlockImports System.IO
Imports System.Collections
Imports System.Collections.Generic
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim arrFiles As ArrayList = New ArrayList()
Dim arrDirs As ArrayList = New ArrayList()
Dim dirpath As String = "D:\MyFolder"
'Retrieve all files in the directory
Dim strFiles() As String = Directory.GetFiles(dirpath)
'Retrieve all sub directories in the directory
Dim strDirs() As String = Directory.GetDirectories(dirpath)
'Add all files to the ArrayList
For Each name As String In strFiles
arrFiles.Add(name)
MessageBox.Show(name) 'It will show the file with full file path.
Next
'Add all files to the ArrayList
For Each name As String In strDirs
arrDirs.Add(name)
MessageBox.Show(name) 'It will show the subfolder with full folder path.
Next
End Sub
End Class
Trackback:
http://forums.microsoft.com:80/MSDN/ShowPost.aspx?PostID=2178642&SiteID=1
http://forums.microsoft.com:80/MSDN/ShowPost.aspx?PostID=2334820&SiteID=1
Best regards,
Martin
- Marked as answer by Martin Xie - MSFT Monday, June 2, 2008 12:16 PM
- Marked as answer by Martin Xie - MSFT Monday, June 2, 2008 12:16 PM
Thursday, May 29, 2008 8:53 AM
All replies
-
Illegal characters in path simply means that the file path contains an illegial character, the illegal characters are:
\ / : * ? < > |
EDIT: oh i see, HOW DID YOU GET THEM ONTO A CD IN THE FIRST PLACE?!?!?!Thursday, May 22, 2008 12:03 PM -
Mooshy wrote: I have a CD that have some folders with illegal names like : <>, null ,etc
These folders contact some files that run properly. I want to run or copy them but I can`t.
I use System.Diagnostics.Process.Start(Path) and also FileCopy but it return an error :
Illegal characters in path. Is it possible to copy these files from these kinds of folders ?
Thank you for your helpTry this to delete illegal names. Add a listbox and set its visible property as false:
Code SnippetDim
change As String Dim file1 As String = "C:\Users\Alessio\Documents\ci.a<.txt"<O.TXT"< P>Code SnippetPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Process.Start(file1)
MsgBox(ex.ToString())
For Each s In split
Me.ListBox1.Items.Add(s)
Next
number =
Me.ListBox1.Items.Countchange = Replace(
Me.ListBox1.Items.Item(number - 1), "<", "") My.Computer.FileSystem.RenameFile(file1, change)file1 = Replace(file1,
"<", "")Process.Start(file1)
End IfMsgBox(
"The new name of the file is" & " " & change) End Try End SubHope it helps.
Ale N.
Thursday, May 22, 2008 2:20 PM -
Thank you for your post. But I think you didn`t notice to these things :
1- I have a folder with Illegal characters not a file.
2- These files are on CD, so I can`t change their names.
3- I want to get files names from this folder and copy them. Not run them !
But thank you anywayThursday, May 22, 2008 2:47 PM -
Mooshy wrote: Thank you for your post. But I think you didn`t notice to these things :
1- I have a folder with Illegal characters not a file.
2- These files are on CD, so I can`t change their names.
3- I want to get files names from this folder and copy them. Not run them !Thank you Cameron and Ale for your friendly help.
Hi Mooshy,
I think you firstly need to do this action in DOS command line manually or programmatically:
copy all files and subfolders (from that folder on CD containing illegal characters) to a legal folder
Xcopy SourceFolder DestinationFolder
Execute Dos command line in VB.NET:
Code SnippetPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Process.Start("Cmd.exe", "/C Xcopy SourceFolder DestinationFolder")
' /C parameter means exiting Cmd.exe after executing command
End Sub
Trackback: http://forums.microsoft.com:80/MSDN/ShowPost.aspx?PostID=2907940&SiteID=1
Then you can iterate/read all files and subfolders under a folder like this:
Code BlockImports System.IO
Imports System.Collections
Imports System.Collections.Generic
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim arrFiles As ArrayList = New ArrayList()
Dim arrDirs As ArrayList = New ArrayList()
Dim dirpath As String = "D:\MyFolder"
'Retrieve all files in the directory
Dim strFiles() As String = Directory.GetFiles(dirpath)
'Retrieve all sub directories in the directory
Dim strDirs() As String = Directory.GetDirectories(dirpath)
'Add all files to the ArrayList
For Each name As String In strFiles
arrFiles.Add(name)
MessageBox.Show(name) 'It will show the file with full file path.
Next
'Add all files to the ArrayList
For Each name As String In strDirs
arrDirs.Add(name)
MessageBox.Show(name) 'It will show the subfolder with full folder path.
Next
End Sub
End Class
Trackback:
http://forums.microsoft.com:80/MSDN/ShowPost.aspx?PostID=2178642&SiteID=1
http://forums.microsoft.com:80/MSDN/ShowPost.aspx?PostID=2334820&SiteID=1
Best regards,
Martin
- Marked as answer by Martin Xie - MSFT Monday, June 2, 2008 12:16 PM
- Marked as answer by Martin Xie - MSFT Monday, June 2, 2008 12:16 PM
Thursday, May 29, 2008 8:53 AM -
Martin,
Your answer is very helpful. However, is there a way to get only the SUBFOLDER names WITHOUT THE PATH?
Although thread is hold, hoping to get a response.
Thank you very much,
Neil
neilThursday, October 29, 2009 4:44 PM -
Yes, it is a simple matter of string manipulation. Check this out:
Dim teststr As String = "http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/7cac830f-a67e-4e34-a9e7-f719240154ca"
- Edited by jinzai Thursday, October 29, 2009 4:52 PM typo
Thursday, October 29, 2009 4:51 PM