Solved

programming delete folder problem - lock by process

Posted on 2011-03-17
8
680 Views
Last Modified: 2012-05-11
Hi Experts

i am trying to rename a folder from C#.
i get an error:
The process cannot access the file because it is being used by another process.  System.IO.IOException

i can't find out which process lock the folder.
i tried to use OpenedFilesView but it not indicate folder locking.

can someone help?

10x
0
Comment
Question by:gudidi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:LeDaouk
ID: 35156452
try a third party application to check wich process is locking the folder. like: unblocker
you can kill all process with it that are locking.
0
 

Author Comment

by:gudidi
ID: 35156511
is there a program that i can use just to know who holds the folder? without kill it?
0
 
LVL 10

Expert Comment

by:John Claes
ID: 35156540
@gudidi

How are you trying to rename the File?
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:gudidi
ID: 35156554
hi

with this command:

Directory.Move(sSilviPath + "\\Components", sSilviPath + "\\Components_Old");

10x
0
 
LVL 81

Expert Comment

by:David Johnson, CD, MVP
ID: 35156750
not sure if the @ sign is needed File.Move(@"C:\MyFile.txt", @"C:\MyNewerFile.txt");
0
 

Author Comment

by:gudidi
ID: 35156769
While i stop the process with sleep command i can NOT change manually the folder name.
but i stop the processes i can cahnge it.
so, i would like to know how to find which process locks me?

10x
0
 
LVL 10

Expert Comment

by:John Claes
ID: 35156864
gudidi:

You found the process that is using one File or the directoryInfo  ! Your program is using it!

Are you somewhere creating a file or writing to a file in the Directory? => Close the stream!
Have you created a DirectoryInfo Object for that Folder? ==> Dispose of that object !
Have you created a FileInfo Object for a file in that folder? ==> Dispose of that object !
Are you running your program from that folder? ==> I'm sorry but you can't change the workingfolders name while running the program inside it

regards
poor beggar

0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 35156870
To find the process, you can use the Sysinternals Handle utility:

     http://technet.microsoft.com/en-us/sysinternals/bb896655

It's a command line utility.  Just type the command below to find the process that's holding the folder or any file in that folder.

      handle myfoldername

The output will be something like this:

C:\>handle c:\temp

Handle v3.45
Copyright (C) 1997-2011 Mark Russinovich
Sysinternals - www.sysinternals.com

TextPad.exe        pid: 5376   type: File           360: C:\Temp
TextPad.exe        pid: 5376   type: File           3E0: C:\Temp

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question