Author Topic: File Deletion  (Read 1037 times)

JTaylor

  • Pundit
  • *****
  • Posts: 927
    • Data & Stuff Inc.
File Deletion
« on: January 17, 2018, 09:21:26 am »
Any suggestions for deleting a LOT of files from a directory in a reasonable amount of time?   I have been processing some files using a COM interface of an application and recently discovered that it doesn't clean up after itself and, as a result, ended up with probably 20-30 million files in my Temp directory.  Can't really tell since getting count would take too long.   Upside is it explains why my computer has been acting so weird.  Downside is I have been deleting files non-stop for over a week and probably still have at least 10-12 million to do.   I have been using a command prompt as well as FileDelete() but would love to be able to get back to my project before another week or two so thought I would ask in case I had missed some option.

Thanks.

Jim

td

  • Tech Support
  • *****
  • Posts: 2653
    • WinBatch
Re: File Deletion
« Reply #1 on: January 17, 2018, 09:45:43 am »
Assuming you don't have anything you want to keep in your temp directory, have you tried "rmdir /s /q yourtempdirnamehere" from a command prompt?
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


JTaylor

  • Pundit
  • *****
  • Posts: 927
    • Data & Stuff Inc.
Re: File Deletion
« Reply #2 on: January 17, 2018, 09:59:37 am »
Had considered that but from my reading it made me think it simply went through and deleted files just like "DEL" would and then remove the directory.   Which would mean it would not save any time.   Am I wrong in my understanding?

I am guessing I am grasping at straws and will simply have to wait but hoping there is something I am missing which will speed up the process.

Jim

td

  • Tech Support
  • *****
  • Posts: 2653
    • WinBatch
Re: File Deletion
« Reply #3 on: January 17, 2018, 11:25:03 am »
Theoretically, rmdir could possibly be faster than del because on an NTFS system the directory's files can be removed from the MFT by index without having to check the files' names.  But it would all depend on how MSFT implemented rmdir and del.   I have never tested this so I am just speculating and don't know how much if any time is gained by using rmdir instead of del.   
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


JTaylor

  • Pundit
  • *****
  • Posts: 927
    • Data & Stuff Inc.
Re: File Deletion
« Reply #4 on: January 17, 2018, 11:42:29 am »
Okay.  Thanks.

Jim

JTaylor

  • Pundit
  • *****
  • Posts: 927
    • Data & Stuff Inc.
Re: File Deletion
« Reply #5 on: February 01, 2018, 08:46:29 am »
Things I have discovered...or at least have come to believe (open to being wrong)...and maybe this will help someone.

1.  There is no fast way to delete files.   Have been at it over a month and still several million to go.   Thinking I should have just done a backup, excluding my Temp directory, and then a restore.
2.  You cannot do something like FileDelete("a*") and it do anything.  Same thing from the command prompt.  It makes you think you are doing something but it is not.  Wasted a bunch of time discovering that little bit of knowledge.  This might be a good thing to include in the WinBatch documentation where you speak of using wildcards.

Jim

td

  • Tech Support
  • *****
  • Posts: 2653
    • WinBatch
Re: File Deletion
« Reply #6 on: February 01, 2018, 10:00:46 am »
Actually FileDelete("a*") does do something.  It deletes any file beginning with the letter 'a' that does not have an extension.    Whereas,   FileDelete("a*.*") deletes any file beginning with the letter 'a' irrespective of the extension.   This behavior has been around in Microsoft's OS since before the days of Windows.  Although I don't believe the cmd del command works that way anymore. 
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


JTaylor

  • Pundit
  • *****
  • Posts: 927
    • Data & Stuff Inc.
Re: File Deletion
« Reply #7 on: February 01, 2018, 10:29:41 am »
Probably just forgot that as with many things  :)    Still might be good to note.   

Jim