Results 1 to 7 of 7

Thread: Exception while deleting a Directory.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2008
    Posts
    204

    Exception while deleting a Directory.

    Hi All,

    In my program I am copying a file into a folder using "file.copy" method and later trying to delete the folder using "Directory.Delete" method. But I am getting an exeption stating "A file in the directory I am trying to delete cannot be accessed as it is used by another process". Can anybody say why this exception is fired and what could be done to resolve this.

    Thanks and Regards,
    Siddaraju.A

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Exception while deleting a Directory.

    I take awild guess, maybe one of the file(s) you are trying to delete is still in use, have checked that?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2008
    Posts
    204

    Re: Exception while deleting a Directory.

    Thanks Opus for the reply. The code line which is causing this error is:
    Code:
    ' "FileToCopy" is a array of type String holding path and name of the file to be copied.
    ' "ToCopyDirectory" is a string variable holding the destination directory name and path 
    
     System.IO.File.Copy(FileToCopy(i), ToCopyDirectory, True)
    This is the line causing the actual error because if I comment this line then my deletion of directory is possible. The method I am using for deletion is :

    Code:
    Directory.Delete(ToCopyDirectory, True)
    Regards,
    Susheelss

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Exception while deleting a Directory.

    Check your useage of .FileCopy.
    According to MSDN the second parameter takes: "The name of the destination file. This cannot be a directory."
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2008
    Posts
    204

    Re: Exception while deleting a Directory.

    No Mr.Opus the destination variable contains the string with file name along with the full directory path.

    Regards,
    Susheelss

  6. #6
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Exception while deleting a Directory.

    OK, the used name did suggest something else.

    What are you doing with the files between the FileCopy and Directory.Delete? Maybe that "File-Action" isn't finished yet.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  7. #7
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Exception while deleting a Directory.

    Quote Originally Posted by Susheelss View Post
    Thanks Opus for the reply. The code line which is causing this error is:
    Code:
    ' "FileToCopy" is a array of type String holding path and name of the file to be copied.
    ' "ToCopyDirectory" is a string variable holding the destination directory name and path 
    
     System.IO.File.Copy(FileToCopy(i), ToCopyDirectory, True)
    This is the line causing the actual error because if I comment this line then my deletion of directory is possible. The method I am using for deletion is :

    Code:
    Directory.Delete(ToCopyDirectory, True)
    Regards,
    Susheelss
    Isn't ToCopyDirectory the new file paths any way?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width