Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File manipulation locks files

Status
Not open for further replies.

stillinlife101

Programmer
Feb 15, 2005
29
US
const string Dellstring = "MarkedForDeletion";

private void RefreshFiles(string Path, Customer[] Cust)
{
DirectoryInfo di = new DirectoryInfo(Path);
FileInfo[] fi = di.GetFiles("cust");
DObject doFilenames = new DObject();
foreach (FileInfo f in fi)
if (new Customer(f.FullName).Name == DelString)
{
doFilenames.AddObject(f.FullName);
}
//Here, I would like to delete the files that have been
//added to the doFilenames list
//How do I force di and fi to unlock the files?
}
 
It's using them. That makes it so I can't delete them. If I try in code, it gives me a file permissions error.
 
Something must be wrong in " DObject doFilenames = new DObject();"

I tried myself (to get files from a dir and delete them) and i had no problem
 
There's no file manipulation in DObjects.

class DObject
{
Object[] objects;
public DObject()
{
}

public void AddObject(object o)
{
int x = objects.GetUpperBound(0);
if (x == -1)
{
objects = new object[0];
objects[0] = 0;
}
else
{
Object[] tempO = objects;
objects = new object[x + 1];
for (int y = 0; y < tempO.GetUpperBound(0); y++)
objects[y] = tempO[y];
objects[x + 1] = o;
}
}

public void RemoveObject(int Index)
{
if (objects.GetUpperBound(0) != -1)
{
if (objects.GetUpperBound(0) == 0)
{
objects = null;
}
else
{
Object[] to = new object[objects.GetUpperBound(0) - 1];
for (int x = 0; x < to.GetUpperBound(0); x++)
{
if (x < Index)
to[x] = objects[x];
if (x > Index)
to[x - 1] = objects[x];
}

}
}
}

}

Dan
 
Try stepping through each line and see which file is locked. Maybe a file is indeed locked by another process.

[wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top