0

I have thousands of files in 39 sub-folders. I do identify around 50 files to delete from sub-folders. I need batch script to delete them together.

Like,

Sub-Folder A Contain > a1,a2,a3,a4 //These all are file name including extension

Sub-Folder B Contain > b1,b2,b3

..........

Sub-Folder Z Contain > z1,z2,z3,z4,z5

I need to Delete,

a3

b1

c7

d5

z2

z4

Hope you can understand my problem. Any help appreciated. Thanks in Advance.

user176705
  • 13
  • 6

2 Answers2

0

In order to delete the files mentioned in your text file, you can perform a for loop like this:

FOR /F "delims=#" %%j IN (your_list.txt) DO ( echo %%j
del %%j
)
Florian Straub
  • 826
  • 9
  • 18
  • thanks for reply but it just open the text file, nothing do – user176705 Nov 24 '17 at 14:32
  • You need inverted commas around %%j (like "%%j") if your paths contain blanks. Can you post the output of the script? – Florian Straub Nov 25 '17 at 21:16
  • Output, after changing with inverted commas just blinking the cmd screen for once. Not delete any file – user176705 Nov 26 '17 at 09:52
  • add ``PAUSE`` at the end of the file in order to see what happens – Florian Straub Nov 27 '17 at 10:53
  • with inverted comma, PAUSE not work it blinking! Without comma: D:\Backup>FOR /F "delims=#" %j IN ('Junk.txt') DO ( echo %j del %j – user176705 Nov 27 '17 at 11:57
  • is the script started from the path in which Junk.txt resides? Maybe try first with a script that only contains one line with ``type Junk.txt`` and another one with ``PAUSE``. If the content of Junk.txt is not shown on the screen, the path is wrong! – Florian Straub Nov 27 '17 at 16:36
  • .bat file & Junk.txt (list of file to be deleted) reside in same path, this path (root folder) also contains all sub-folders. Tried with one line .txt, it just open the text file but not the content (file which will be deleted) – user176705 Nov 27 '17 at 18:42
  • Does it show the content of the text file? What else does it show? – Florian Straub Nov 29 '17 at 15:24
  • According to [this](https://stackoverflow.com/questions/155932/how-do-you-loop-through-each-line-in-a-text-file-using-a-windows-batch-file) one can obmit the TYPE command, so I updated my solution. if you remove the DEL statement and keep the PAUSE at the end: Do you see the filenames of the files to delete? – Florian Straub Nov 30 '17 at 14:07
  • Now it different in result: 'C:\Users\ABC\Desktop\Backup>( echo QSMTEX del QSMTEX ) QSMTEX Could Not Find C:\Users\ABC\Desktop\Backup\QSMTEX' – user176705 Dec 01 '17 at 12:02
0

I myself able to create the script,

FOR /F "delims=#" %%j IN (list_of_to_be_deleted.txt) DO ( del /s %%j
echo %%j has been Deleted!
)
user176705
  • 13
  • 6