471,350 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

System.IO.File.Copy changes the current Directory

Avi
Hi All,
I am using following function to copy a file.

System.IO.File.Copy(sourcefile,destFile);

I am giving absolute path in destFile. (eg. "C:\avi.txt")

After execution of this call, my current directory changes to "C:\".
How can I prevent this? I want my current directory to remain
unchanged.

One way will be calling GetCurrentDirectory() and SetCurrentDirectory()
in sequence.

string currentdir = Directory.GetCurrentDirectory();
// Copy file
System.IO.File.Copy("c:\\a.txt",destFile);
Directory.SetCurrentDirectory(currentdir);

Is there any better solution to this problem.

Thanks and Regards,
Avi

Jan 9 '06 #1
1 5793
Hi,

Is there any better solution to this problem.


Just store the original folder in a variable and always use absolute paths.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Penn Markham | last post: by
8 posts views Thread by Siemel Naran | last post: by
8 posts views Thread by A P | last post: by
reply views Thread by Glenn Venzke | last post: by
3 posts views Thread by Frank Uray | last post: by
reply views Thread by P Pulkkinen | last post: by
5 posts views Thread by Lilith | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.