0

I have 30 folders, each with about 1700 files in them. I'd like to delete 500 files from each of these folders. What is the best way to do this using command prompt?

This question shows how to empty out files and this question shows how to do it in python but otherwise, there doesn't seem to be a way of deleting a specific number of files.

Let me know if you need any further information, thanks!

Andrew Earl
  • 353
  • 1
  • 5
  • 16

1 Answers1

-1

It's very easy to do in Linux. So you can download Git for Windows and run Linux commands in Windows. Please try this in a test folder/files first. You can not recover files once deleted.

Let's say you have 3 files (my-file-1.txt, my-file-2.txt, my-file-3.txt) in your directory. Then go to the directory and execute commands.

$ rm -rf my-file-1.txt               # remove my-file-1.txt only
$ rm -rf my-file-1.txt my-file-3.txt # remove my-file-1 and 3
$ rm -rf my-file-{1,3}.txt           # remove my-file-1 and 3
$ rm -rf *.txt                       # remove all txt files
$ rm -rf my-file-*.txt               # remove all txt files begin with my-file
Abu Shoeb
  • 4,747
  • 2
  • 40
  • 45
  • That answers my question, but not fully because I still have to name each of the files within each of the subfolders. If I have 30 folders, each with about 1700 uniquely named files the above method is very time consuming. – Andrew Earl May 03 '18 at 11:55
  • Do you have any pattern in the file name for the files to be deleted? Otherwise it’s very likely to mention those name individually in the deletion process – Abu Shoeb May 03 '18 at 15:38
  • The question clearly asks how to delete files in Windows, not in Linux. – Asif Feb 19 '22 at 00:16
  • @Asif you are right but these days many of the command line one windows supports Linux commands and Git Bash is one of them for which I recommended to use it. I'll update my answer to adjust all comments. Thanks – Abu Shoeb Mar 03 '22 at 15:14