|
-
Apr 18th, 2003, 07:53 PM
#1
Thread Starter
Lively Member
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:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim fsw2 As New FileSystemWatcher("c:\3do")
Dim source As String = "c:\3do\*.*"
Dim dest As String = "C:\Inetpub\wwwroot\logs"
Me.Hide()
Dim check As WaitForChangedResult
check = fsw2.WaitForChanged(WatcherChangeTypes.Created)
If check.ChangeType.Created Then
System.IO.File.Copy(source, dest, True)
End If
End Sub
12/32/84 - I need some code to make me a sandwhich.
-
Apr 18th, 2003, 08:55 PM
#2
Fanatic Member
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.
-
Apr 18th, 2003, 09:25 PM
#3
Thread Starter
Lively Member
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.
-
Apr 18th, 2003, 09:44 PM
#4
Fanatic Member
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. ^_^
-
Apr 18th, 2003, 09:45 PM
#5
Thread Starter
Lively Member
Thats the thing. The files dont exist in the other dir...
12/32/84 - I need some code to make me a sandwhich.
-
Apr 18th, 2003, 09:51 PM
#6
Fanatic Member
duh, so am I... that's what I get for not testing what I post! *pound pound pound* just a minute...
-
Apr 18th, 2003, 09:53 PM
#7
Fanatic Member
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)
-
Apr 18th, 2003, 10:05 PM
#8
Thread Starter
Lively Member
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.
-
Apr 18th, 2003, 10:15 PM
#9
Fanatic Member
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.
-
Apr 18th, 2003, 10:47 PM
#10
Thread Starter
Lively Member
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.
-
Apr 19th, 2003, 09:02 AM
#11
yay gay
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/
-
Apr 19th, 2003, 11:58 AM
#12
Fanatic Member
I don't understand exactly what your code does or how it relates to File.Copy/FileSystemWatcher?
-
Apr 19th, 2003, 02:01 PM
#13
yay gay
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/
-
Apr 19th, 2003, 02:17 PM
#14
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|