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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting over a million files on C Drive 5

Status
Not open for further replies.

grechmt

MIS
Oct 2, 2001
11
US
In a nutshell, we had a Windows 2003 (SP1) server or application failure that put over 1.6 million TMP files in the root directory of the C drive. Each files is 1K or 2K in size. The server still runs but when I try to delete them it goes very slow (the deleting). I booted into Safe Mode + Command Prompt and tried this command "C:\> delete *.tmp" but I stopped it after serveral hours. Are there any other ideas to delete this many files expediently?
 
It is understandable that it is slow since it has to enumerate 1.6million files for deletion. Although other tools can be used, I think the del command should be efficient. I would recommend the following though;

1. Ensure you have adequate RAM available. Try disabling some applications/services in order to increase the avail amount
2. You say that DEL stops after a few hours.. Does it actually delete any files during this time. Try running DEL using referring to specific files ex) del 1*.tmp for instance
3. Defragment your C: drive and attempt another deletion.

I would really like to know what kind of application failure would cause this. I would certainly get rid of this app
Hope this helps.
 
This server is a dedicated backup server that runs only two applications: (1) CA Arcserve Brightstor 11.5 and (2) Honeywell Symantec Live State Backup. We were not using the Symantec Live State software. The TMP files I found all "seem" to be Brightstor generated files. I had to reinitialize the Brightstor database after I discovered the problem.
 
Test it first. Try deleting just one file. If it works, then you know that doing a wildcard delete should work as well. Everything else is just waiting for it to complete.

Even if it fails partway through the process, it should still have deleted some of the files. At that point you can just repeat the process.
 
Have to agree - delete using the del command from the command prompt. And yes, it's going to take a LONG time. When I delete temporary internet files in the past, 10,000 can take a minute or more... so 3 hours MINIMUM, but the time could also increase depending on exactly how it deletes. Know the count now, run the command and time it.
 
A very long time. I once wrote a script that would scan a fileshare with several million files and generate a text file with the name/path of every file that hadn't been accessed in over a year so that we could archive them. It took several days to complete. You don't have all the overheard of writing names to a text file or crawling various directories, but you do have the overhead of doing a delete.
 
Thanks to all. The simple Delete command worked but, as stated above, it took hours to delete them all. Anyway I'm glad it worked. Also the drive needed to be defraged afterwards as mentioned in one of the posts above.

Thanks again,
Michael
 
You will probably see faster deletions with WMI.

Code:
On Error Resume Next
strComputer = "."
[green]'Change path below to directory to clean out[/green]
strFolder = "C:\Users\markmac\AppData\Local\Temp"

Dim objWMIService, colFileList, objFile, objFolder, colSubfolders, colSubfolders2
Dim strFolderName, arrFolders()
intSize = 0


Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='"& strFolder &"'} Where " _
        & "ResultClass = CIM_DataFile")

If colFileList.Count = 0 Then
    Wscript.Echo "There were no files in the folder."
Else
    For Each objFile In colFileList
        objFile.Delete
    Next
End If

[green]'Uncomment the next line to prevent deletion of subdirectories.[/green]
[green]'Wscript.Quit[/green]

Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolder & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")

ReDim Preserve arrFolders(intSize)
arrFolders(intSize) = strFolder
intSize = intSize + 1

For Each objFolder in colSubfolders
	GetSubFolders strFolder
Next

Sub GetSubFolders(strFolder)
	Set colSubfolders2 = objWMIService.ExecQuery _
	("Associators of {Win32_Directory.Name='" & strFolder & "'} " _
	& "Where AssocClass = Win32_Subdirectory " _
	& "ResultRole = PartComponent")
	
	For Each objFolder2 in colSubfolders2
		strFolder = objFolder2.Name
		ReDim Preserve arrFolders(intSize)
		arrFolders(intSize) = strFolder
		intSize = intSize + 1
		GetSubFolders strFolder
	Next
End Sub

For i = Ubound(arrFolders) to 0 Step -1
	strFolder = arrFolders(i)
	strFolder = Replace(strFolder, "\", "\\")
	Set colFolders = objWMIService.ExecQuery _
	("Select * from Win32_Directory where Name = '" & strFolder & "'")
	
	For Each objFolder in colFolders
		errResults = objFolder.Delete
	Next
Next

msgbox "done"

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Whoa - hold on.

I think the files he needs to kill are in the root of C:

I don't see a filter for the temp files in there, so that script might try and kill c:\*.* ? Might make for an interesting weekend! :)

Or did I miss something?

Pat Richard, MCSE MCSA:Messaging CNA
Microsoft Exchange MVP
Want to know how email works? Read for yourself -
 
The script only deletes what is in the target folder:
strFolder = "C:\Users\markmac\AppData\Local\Temp"

But good catch Pat, I did not read the original post carefully enough to see that the temp files were in the root of C rather than the Temp folder which is what I wrote the script for.

So here is a modified version for killing those files in the root of C that are TMP files.

Code:
On Error Resume Next
strComputer = "."
'Change path below to directory to clean out
strFolder = "C:\"

Dim objWMIService, colFileList, objFile, objFolder
Dim strFolder


Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='"& strFolder &"'} Where " _
        & "ResultClass = CIM_DataFile")

If colFileList.Count = 0 Then
    Wscript.Echo "There were no files in the folder."
Else
    For Each objFile In colFileList
    	If LCase(Right(objFile.Name,3)) = "tmp" Then
          objFile.Delete
        End If
    Next
End If


I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top