-
Jun 19th, 2014, 05:55 AM
#1
Thread Starter
Addicted Member
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
-
Jun 19th, 2014, 06:06 AM
#2
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!
-
Jun 19th, 2014, 07:28 AM
#3
Thread Starter
Addicted Member
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
-
Jun 19th, 2014, 08:38 AM
#4
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!
-
Jun 19th, 2014, 11:02 PM
#5
Thread Starter
Addicted Member
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
-
Jun 20th, 2014, 03:38 AM
#6
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!
-
Jun 22nd, 2014, 11:14 AM
#7
Re: Exception while deleting a Directory.
Originally Posted by Susheelss
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|