C
C#2y ago
Silme94

Copying File Error (not working)

Hello ! I was doing an app with Microsoft visual studio 2022 and i wanted to copy an exe to file but it's not working. I dont know how to fix it
public void run()
{
foreach(string i in Directory.GetDirectories("C:\\Users\\" + Environment.UserName + "\\appdata\\roaming"))
{
if (i == "C:\\Users\\" + Environment.UserName + "\\appdata\\roaming\\FplProject_IDE")
{
if_dir_in_path = true;
break;

}
else
{
if_dir_in_path = false;
break;
}
}

if (!if_dir_in_path)
{
Directory.CreateDirectory("C:\\Users\\" + Environment.UserName + "\\appdata\\roaming\\FplProject_IDE");
try
{
File.Copy(Directory.GetCurrentDirectory() + "\\French_Programming_Language.exe", "C:\\Users\\" + Environment.UserName + "\\appdata\\roaming\\FplProject_IDE\\French_Programming_Language.exe", true);
}
catch (IOException iox)
{
MessageBox(new IntPtr(0), Convert.ToString(iox), "Error", 0);
}
}
public void run()
{
foreach(string i in Directory.GetDirectories("C:\\Users\\" + Environment.UserName + "\\appdata\\roaming"))
{
if (i == "C:\\Users\\" + Environment.UserName + "\\appdata\\roaming\\FplProject_IDE")
{
if_dir_in_path = true;
break;

}
else
{
if_dir_in_path = false;
break;
}
}

if (!if_dir_in_path)
{
Directory.CreateDirectory("C:\\Users\\" + Environment.UserName + "\\appdata\\roaming\\FplProject_IDE");
try
{
File.Copy(Directory.GetCurrentDirectory() + "\\French_Programming_Language.exe", "C:\\Users\\" + Environment.UserName + "\\appdata\\roaming\\FplProject_IDE\\French_Programming_Language.exe", true);
}
catch (IOException iox)
{
MessageBox(new IntPtr(0), Convert.ToString(iox), "Error", 0);
}
}
38 Replies
Silme94
Silme942y ago
Silme94
Silme942y ago
Most interesting code (where i got the error) :
if (!if_dir_in_path)
{
Directory.CreateDirectory("C:\\Users\\" + Environment.UserName + "\\appdata\\roaming\\FplProject_IDE");
try
{
File.Copy(Directory.GetCurrentDirectory() + "\\French_Programming_Language.exe", "C:\\Users\\" + Environment.UserName + "\\appdata\\roaming\\FplProject_IDE\\French_Programming_Language.exe", true);
}
catch (IOException iox)
{
MessageBox(new IntPtr(0), Convert.ToString(iox), "Error", 0);
}
if (!if_dir_in_path)
{
Directory.CreateDirectory("C:\\Users\\" + Environment.UserName + "\\appdata\\roaming\\FplProject_IDE");
try
{
File.Copy(Directory.GetCurrentDirectory() + "\\French_Programming_Language.exe", "C:\\Users\\" + Environment.UserName + "\\appdata\\roaming\\FplProject_IDE\\French_Programming_Language.exe", true);
}
catch (IOException iox)
{
MessageBox(new IntPtr(0), Convert.ToString(iox), "Error", 0);
}
cap5lut
cap5lut2y ago
its saying that it cant find the file, so the path has to be wrong (or the file doesnt exist)
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Servator
Servator2y ago
dammit stupid sandbox this works
Servator
Servator2y ago
Servator
Servator2y ago
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
Don't put hardcoded path Combine paths with Path.Combine()
Servator
Servator2y ago
Anchy
Anchy2y ago
don't forget to set the Build Action to Content for the file as well
Anchy
Anchy2y ago
Silme94
Silme942y ago
Thanks guys im going to test it tomorrow !
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ero
ero2y ago
Path.Join
Silme94
Silme942y ago
who can help solving this error ?
Silme94
Silme942y ago
InvalidOperatorExecption i think its working but i got this error
Servator
Servator2y ago
What's the error
Silme94
Silme942y ago
here this at Program.cs
Servator
Servator2y ago
but what does it says It just shows where it is
Silme94
Silme942y ago
InvalidOperatorExecption
Servator
Servator2y ago
Servator
Servator2y ago
Click this bottom left
Silme94
Silme942y ago
ok i got 20 error 💀
Servator
Servator2y ago
-_-
Silme94
Silme942y ago
btw its french
Silme94
Silme942y ago
Silme94
Silme942y ago
bro i think i give up 💀 im going to restart
Servator
Servator2y ago
before you deleting a control on form click control first and delete its events from Properties window Right Click -> Reset bla bla (i dont remember) then remove its code otherwise its gonna throw an error
Silme94
Silme942y ago
@Samarichitane look he tell that path is not correct but it is
Silme94
Silme942y ago
Silme94
Silme942y ago
Servator
Servator2y ago
Servator
Servator2y ago
what does it says there
Silme94
Silme942y ago
it say that he didn't found the path
Servator
Servator2y ago
Are you running vs as admin mode ?
Silme94
Silme942y ago
no
Servator
Servator2y ago
try that
Silme94
Silme942y ago
alr same thing 💀 its weird 💀 💀 the same path.. but not the same...
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View