Problem with ";" in File/Folder-name

oldfarth

New member
Joined
Feb 25, 2009
Messages
3
Programming Experience
10+
Hello!

i have a problem with the following snippet:
(working on Visual Studio 2008 , Net-Framwork 3.5, all Service-packs)
Vb.Net

My.Computer.FileSystem.RenameFile(cc + TmpName + cc, cc + OnlyName + cc)

Cc equals to Chr(34)
or also

My.Computer.FileSystem.RenameFile(TmpName,OnlyName)

The Problem occurs if in one of the Strings the Character ";" is embedded.

Don't ask me wy this Char is in the Filename - it is.

An "Illegal Character in Path" exception occurs. Is this a good known problem?
 
My.Computer.FileSystem.RenameFile(cc + TmpName + cc, cc + OnlyName + cc)

Cc equals to Chr(34)
Double-quote characters is not valid in file names.
The Problem occurs if in one of the Strings the Character ";" is embedded.
Only the destination name. It is a bug in RenameFile method, it checks for path separator ; used in environment variables. Since ; is valid in file names use IO.File.Move method instead.
 
Thanks for the real fast answer!

I was on this way, but i Don't think about environment variables!

also you cannot take the Char "&"

I found a workaround like this:

dim ProcId as integer
Von = Chr(34) + von + Chr(34)
Zu = Chr(34) + zu + Chr(34)
cmd = "Cmd.EXE /C RENAME " + Von + " " + Zu
ProcID = Shell(cmd, AppWinStyle.Hide)

this work for folder and/or Filenames!
 
i Don't think about environment variables!
Neither did they apparently.
VB.NET:
also you cannot take the Char "&"
No, neither My...RenameFile or File.Move has any problems with & char.
 
Yes you are right - may be is stay too long on my line(ok, i'm German) i found out, it will not work with embedded in Chr(34)! i dont' konw wy- but it's ok!
Thnks
 
Back
Top