Skip to main content
GameDev.net gamedev.net
🔒 Locked

File Replace: Invalid Path Problem

Started by Drakken255 Aug 3, 2012 at 11:33 AM 2 replies 5.4k views
Original Post
Drakken255
Drakken255
When I use this line in debug, it works absolutely fine, but not when I build and run the release binary:


File.Replace(patchCraftDataPath + @"Temp\PatchCraft.ptch", path, patchCraftDataPath + @"Temp\PatchCraft.old");


path is equal to "C:\\Users\\\\Documents\\Visual Studio 2010\\Projects\\PatchCraft\\PatchCraft\\bin\\Debug\\PatchCraft.exe"

When I run the binary, I run it in this folder: "C:\Users\\Documents\PatchCraft\Publish\PatchCraft"
Thus, the filepath argument my patcher gets and in turn the path var should be: C:\\Users\\\\Documents\\PatchCraft\\Publish\\PatchCraft\\PatchCraft.exe"

My exception text when I run the binary:
************** Exception Text **************
System.ArgumentException: The path is not of a legal form.
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
at System.IO.Path.GetFullPathInternal(String path)
at System.IO.File.InternalReplace(String sourceFileName, String destinationFileName, String destinationBackupFileName, Boolean ignoreMetadataErrors)
at System.IO.File.Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName)
at PatchCraft_Patcher.PatchCraftPatcher.PatchDownloadComplete(Object sender, AsyncCompletedEventArgs e)
at System.Net.WebClient.OnDownloadFileCompleted(AsyncCompletedEventArgs e)
at System.Net.WebClient.DownloadFileOperationCompleted(Object arg)

Why is the binary counting the path variable as invalid?
rip-off
rip-off
From the documentation: http://msdn.microsoft.com/en-us/library/system.io.fileinfo.fileinfo.aspx

The file name is empty, contains only white spaces, or contains invalid characters.
[/quote]


Thus, the filepath argument my patcher gets and in turn the path var should be
[/quote]
Can you log the actual path somewhere?
Drakken255
Drakken255
It turns out that somehow, when it was in Debug, it wrote "C:\" while in binary, it wrote":\" so I'm checking all my filepath cutting again. The path actually comes in starting "file:\\"
Drakken255
Drakken255
And That was it! At first it would chop 7 letters off, because I thought "\\" counted as two letters, when it only counts as one. So "file:\\C:\\" turned into ":\\" with 7 chopped, and "C:\\" with 6 chopped. Thanks for the log suggestion.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.