Results 1 to 14 of 14

Thread: Illegal characters in path.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83

    Illegal characters in path.

    I'm getting an error with the following code. "Illegal characters in path."
    I am trying to watch a certain dir for file (Log files) and when they are
    uploaded via ftp move them to another dir. The error occurs on the last
    line where I try and copy the files.

    Anyone know how to fix this or maybe a better way to do it?
    I'm also looking for a way to just check it every.. say 10 minutes.

    An unhandled exception of type 'System.ArgumentException' occurred in
    mscorlib.dll
    Additional information: Illegal characters in path.
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
    2. System.EventArgs) Handles MyBase.Load
    3. Dim fsw2 As New FileSystemWatcher("c:\3do")
    4. Dim source As String = "c:\3do\*.*"
    5. Dim dest As String = "C:\Inetpub\wwwroot\logs"
    6. Me.Hide()
    7. Dim check As WaitForChangedResult
    8. check = fsw2.WaitForChanged(WatcherChangeTypes.Created)
    9. If check.ChangeType.Created Then
    10. System.IO.File.Copy(source, dest, True)
    11. End If
    12. End Sub
    12/32/84 - I need some code to make me a sandwhich.

  2. #2
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    What exactly are the characters it is choking on?

    Also, I don't believe it would save you very much overhead - probably it would even cost you a lot more overhead - to use some other method of checking for filesystem changes than the FileSystemWatcher. The watcher only generates an event when a change is made, and the only event data recorded is that relevent to the change. If you were going to check every 10 minutes you'd have to basically explore the filesystem and record all the attributes you want to check by sticking them in some kind of array. This array could be very (VERY) large depending on how many files/directories you are monitoring, and the compare logic would likely not be very simple.

    You can filter what filesystem change events you examine with the FileSystemWatcher.NotifyFilter property:
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatcherclassnotifyfiltertopic.htm

    edit: Oh duh I see what you mean. File.Copy doesn't seem to like wildcards.

    How about something like
    Code:
    Dim diDirectory As New DirectoryInfo("c:\3do")
    Dim arrFiles(), fiFile As FileInfo
    
    Try
        arrFiles = diDirectory.GetFiles()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    
    For Each fiFile In arrFiles
        System.IO.File.Copy(fiFile.FullName, "c:\inetpub\wwwroot\logs", True)
    Next
    Last edited by Slow_Learner; Apr 18th, 2003 at 09:07 PM.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    Well thats better then the mess I created.

    But know I get another error:
    An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

    Additional information: Cannot create a file when that file already exists.

    So I tryed moving the files. Same thing. !!!
    12/32/84 - I need some code to make me a sandwhich.

  4. #4
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    a simple fix is to just delete the files if they exist... not sure why it won't overwrite, the docs say file.copy will. ^_^

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    Thats the thing. The files dont exist in the other dir...
    12/32/84 - I need some code to make me a sandwhich.

  6. #6
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    duh, so am I... that's what I get for not testing what I post! *pound pound pound* just a minute...

  7. #7
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Misleading error message. The destination parameter expects a whole path + filename. Instead of
    System.IO.File.Copy(fiFile.FullName, "c:\inetpub\wwwroot\logs", True)

    try

    System.IO.File.Copy(fiFile.FullName, "c:\inetpub\wwwroot\logs" + fiFile.Name, True)

    edit: err, that's
    System.IO.File.Copy(fiFile.FullName, "c:\inetpub\wwwroot\logs\" + fiFile.Name, True)

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    Thank you! That works perfectly.

    Any chance you know how you get this to run all the time?
    After it copies the files it stops monitoring the dir.
    12/32/84 - I need some code to make me a sandwhich.

  9. #9
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Be sure you are watching for all the possible events. Each file operation (create, change, rename, delete, etc) generates a different event, which you will need to account for.

    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatchermemberstopic.htm

    Beyond that, if you don't have invoke Close or whatever, you shouldn't have to do anything complicated.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    Excellent. Thanks for all your help. I had been working on this most the day.
    12/32/84 - I need some code to make me a sandwhich.

  11. #11
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    damn i got the "illegals characters in path" when tryed reflection but it is pointing to the end of the code to the closing brace so i dont get it..:
    Code:
    				public static bool IsInstanciable(string fileName) {
    					try {
    						Assembly asm = Assembly.LoadFrom(fileName);
    						Form form;
    						Type[] types = asm.GetTypes();
    
    						foreach (Type type in types) {
    							if (type.IsSubclassOf(typeof(Form))) {
    								form = (Form)Activator.CreateInstance(type);
    							
    								foreach (Control plugin in form.Controls) {
    									Type tmp = plugin.GetType();
    									PluginPanel p = new PluginPanel();
    
    									if (tmp.IsInstanceOfType(p) && p._CallingMethod == INTERFACE_TYPE.Instanciable) {
    										return true;
    									}
    								}
    							}
    						}
    					} catch { return false;	}
    					return false;
    				}
    \m/\m/

  12. #12
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    I don't understand exactly what your code does or how it relates to File.Copy/FileSystemWatcher?

  13. #13
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    noone ever said it had something to do with fylesystem watcher thu i found what the problem was..some methods support wildcards and some not so one must be becareful
    \m/\m/

  14. #14
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Aha I guess your problem was with Assembly.LoadFrom(fileName)?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width