C
C#•3y 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
Silme94OP•3y ago
Silme94
Silme94OP•3y 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
cap5lut•3y ago
its saying that it cant find the file, so the path has to be wrong (or the file doesnt exist)
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Servator
Servator•3y ago
dammit stupid sandbox this works
Servator
Servator•3y ago
Servator
Servator•3y ago
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
Don't put hardcoded path Combine paths with Path.Combine()
Servator
Servator•3y ago
Anchy
Anchy•3y ago
don't forget to set the Build Action to Content for the file as well
Anchy
Anchy•3y ago
Silme94
Silme94OP•3y ago
Thanks guys im going to test it tomorrow !
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
ero
ero•3y ago
Path.Join
Silme94
Silme94OP•3y ago
who can help solving this error ?
Silme94
Silme94OP•3y ago
InvalidOperatorExecption i think its working but i got this error
Servator
Servator•3y ago
What's the error
Silme94
Silme94OP•3y ago
here this at Program.cs
Servator
Servator•3y ago
but what does it says It just shows where it is
Silme94
Silme94OP•3y ago
InvalidOperatorExecption
Servator
Servator•3y ago
Servator
Servator•3y ago
Click this bottom left
Silme94
Silme94OP•3y ago
ok i got 20 error 💀
Servator
Servator•3y ago
-_-
Silme94
Silme94OP•3y ago
btw its french
Silme94
Silme94OP•3y ago
Silme94
Silme94OP•3y ago
bro i think i give up 💀 im going to restart
Servator
Servator•3y 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
Silme94OP•3y ago
@Samarichitane look he tell that path is not correct but it is
Silme94
Silme94OP•3y ago
Silme94
Silme94OP•3y ago
Servator
Servator•3y ago
Servator
Servator•3y ago
what does it says there
Silme94
Silme94OP•3y ago
it say that he didn't found the path
Servator
Servator•3y ago
Are you running vs as admin mode ?
Silme94
Silme94OP•3y ago
no
Servator
Servator•3y ago
try that
Silme94
Silme94OP•3y ago
alr same thing 💀 its weird 💀 💀 the same path.. but not the same...
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?