I am writing a little appliation. One process I want to do is to copy a
folder to a different location, delete the contents of the original
folder, and fill the original location with new files. It's a relatively
simple process, but I've run into a little snag. With Full Control
privileges, I am getting an error stating that I do not have permission
to delete a file in the original location.
I do not believe that this file is in use, because I can successfully
use Directory.Move( ) without a problem. So I'm beginning to wonder if
there's a problem with my CopyDirectory() method:
public void CopyDirectory(s tring source, string destination)
{
if (destination[destination.Len gth - 1] !=
Path.DirectoryS eparatorChar)
destination += Path.DirectoryS eparatorChar;
if (!Directory.Exi sts(destination ))
Directory.Creat eDirectory(dest ination);
string[] files = Directory.GetFi leSystemEntries (source);
foreach (string fileElement in files)
{
// Subdirectories
if (Directory.Exis ts(fileElement) )
CopyDirectory(f ileElement,
destination + Path.GetFileNam e(fileElement)) ;
// Files in current directory
else
File.Copy(fileE lement,
destination + Path.GetFileNam e(fileElement), true);
}
}
Since Directory.Move( ) works, I know that I can move the original,
create a new folder of the same name in the original's original
location, and populate the new folder. But since this was my first
thought, I want to find out why I'm getting a permissions error.
Anyone have any thoughts? (I apologize if CopyDirectory() isn't
formatted correctly. I'm posting from a Web-based client. My employer
blocks NNTP).
--
Sent via .NET Newsgroups
folder to a different location, delete the contents of the original
folder, and fill the original location with new files. It's a relatively
simple process, but I've run into a little snag. With Full Control
privileges, I am getting an error stating that I do not have permission
to delete a file in the original location.
I do not believe that this file is in use, because I can successfully
use Directory.Move( ) without a problem. So I'm beginning to wonder if
there's a problem with my CopyDirectory() method:
public void CopyDirectory(s tring source, string destination)
{
if (destination[destination.Len gth - 1] !=
Path.DirectoryS eparatorChar)
destination += Path.DirectoryS eparatorChar;
if (!Directory.Exi sts(destination ))
Directory.Creat eDirectory(dest ination);
string[] files = Directory.GetFi leSystemEntries (source);
foreach (string fileElement in files)
{
// Subdirectories
if (Directory.Exis ts(fileElement) )
CopyDirectory(f ileElement,
destination + Path.GetFileNam e(fileElement)) ;
// Files in current directory
else
File.Copy(fileE lement,
destination + Path.GetFileNam e(fileElement), true);
}
}
Since Directory.Move( ) works, I know that I can move the original,
create a new folder of the same name in the original's original
location, and populate the new folder. But since this was my first
thought, I want to find out why I'm getting a permissions error.
Anyone have any thoughts? (I apologize if CopyDirectory() isn't
formatted correctly. I'm posting from a Web-based client. My employer
blocks NNTP).
--
Sent via .NET Newsgroups
Comment