Do not have permission...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeremy

    #1

    Do not have permission...

    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

  • Chris

    #2
    Re: Do not have permission...

    Jeremy wrote:[color=blue]
    > 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
    > http://www.dotnetnewsgroups.com[/color]

    Just a thought, but you are trying to Delete the file after the Copy
    correct? Is it the case that the file isn't done copying yet when you
    try to delete it, therefore making it "in use"? Like I said, just a
    thought.


    Chris

    Comment

    • Jeremy

      #3
      Re: Do not have permission...

      Howdy, Chris.

      I don't think that would be the problem. Both operations are ran in the
      same thread, and the deletion comes after the copy. But it is worth
      checking into. Thanks for the thought, and hopefully that will be the
      problem =)

      Thanks a bunch!

      --
      Sent via .NET Newsgroups

      Comment

      Working...