I am programming in c# and want to copy a folder with subfolders from a flash disk to startup.
Here is my code:
private void copyBat() { try { string source_dir = "E:\\Debug\\VipBat"; string destination_dir = "C:\\Users\\pc\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup"; if (!System.IO.Directory.Exists(destination_dir)) { System.IO.Directory.CreateDirectory(destination_dir); } // Create subdirectory structure in destination foreach (string dir in Directory.GetDirectories(source_dir, "*", System.IO.SearchOption.AllDirectories)) { Directory.CreateDirectory(destination_dir + dir.Substring(source_dir.Length)); } foreach (string file_name in Directory.GetFiles(source_dir, "*.*", System.IO.SearchOption.AllDirectories)) { File.Copy(file_name, destination_dir + file_name.Substring(source_dir.Length), true); } } catch (Exception e) { MessageBox.Show(e.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
I got an error:
Could not find a part of the path E:\Debug\VipBat
If you've been getting this error message on the Command Prompt, check whether you're typing the correct path or not. Most of the time, this is a human error where users are putting in the wrong path or name on the command line. So, go through your command again and ensure that the path is typed correctly.
You can disable one of the settings in security tab > custom level > "Include local directory path when uploading files to a server" in IE and then try again.
That's all about how to solve "The system cannot find the path specified." error while running the program from the command prompt. The root cause of this error is invalid directories, sub-directories in the PATH environment variable, just remove them and the error will be solved.
You use Server. MapPath to resolve the path on the web server. So if you want to save your upload file to a folder called Uploads in the root directory, you would do this to get the correct path: var path = Server.
The error is self explanatory. The path you are trying to access is not present.
string source_dir = "E:\\Debug\\VipBat\\{0}";
I'm sure that this is not the correct path. Debug
folder directly in E:
drive looks wrong to me. I guess there must be the project name folder directory present.
Second thing; what is {0}
in your string. I am sure that it is an argument placeholder because folder name cannot contains {0}
such name. So you need to use String.Format()
to replace the actual value.
string source_dir = String.Format("E:\\Debug\\VipBat\\{0}",variableName);
But first check the path existence that you are trying to access.
There's something wrong. You have written:
string source_dir = @"E:\\Debug\\VipBat\\{0}";
and the error was
Could not find a part of the path E\Debug\VCCSBat
This is not the same directory.
In your code there's a problem, you have to use:
string source_dir = @"E:\Debug\VipBat"; // remove {0} and the \\ if using @
or
string source_dir = "E:\\Debug\\VipBat"; // remove {0} and the @ if using \\
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With