Hack Forums
[Shell] Delete all .exe files in a folder? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] Delete all .exe files in a folder? (/showthread.php?tid=5845681)



Delete all .exe files in a folder? - boykanyon123 - Jun 7, 2018

Hello guys,

Can someone assist me, I need to delete all the .exe files in one specific folder without deleting the subfolder into it. Preferably a 1 liner command.

Is it possible to delete that exe file even it its running? By force delete?

Thanks!


RE: Delete all .exe files in a folder? - Sir-Teabag - Jun 7, 2018

Well you could search in the folder for ".exe", then CTRL + A, and then delete all.

Or if you really want to use batch, try

Code
del /Q *.exe
^make sure the batch file is in the folder containing the EXE files.


RE: Delete all .exe files in a folder? - HFDone - Jun 7, 2018

DEL https://ss64.com/nt/del.html
/S Delete from all Subfolders (DELTREE)
/Q Quiet mode, do not give a Yes/No Prompt before deleting.


RE: Delete all .exe files in a folder? - b00st3d - Jun 7, 2018

You don't have to do it in batch but you can do it in CMD/Powershell. Just hold Shift and right click inside the folder. In the context menu, you'll see open CMD window here or Open Powershell window here. click that and issue the cmd provided by Sir-Teabag.

Code
del /Q *.exe


Ok after testing in powershell, the command is

Code
remove-item *.exe



RE: Delete all .exe files in a folder? - boykanyon123 - Jun 7, 2018

How about kill all task on a specific folder ?


RE: Delete all .exe files in a folder? - Sir-Teabag - Jun 8, 2018

(Jun 7, 2018 07:24 PM)boykanyon123 Wrote:  How about kill all task on a specific folder ?

For that, you may need a little more advanced looping sequence. How many tasks are there? you might have to do them individually


RE: Delete all .exe files in a folder? - boykanyon123 - Jun 8, 2018

(Jun 8, 2018 05:56 AM)Sir-Teabag Wrote:  For that, you may need a little more advanced looping sequence. How many tasks are there? you might have to do them individually

Lets just say 2 task on a specific folder? Do i have to manual it?


RE: Delete all .exe files in a folder? - Sir-Teabag - Jun 8, 2018

(Jun 8, 2018 09:15 AM)boykanyon123 Wrote:  Lets just say 2 task on a specific folder? Do i have to manual it?

Well whatever is easier. Personally I would manually do it but you can use Batch if you want.

First, find the PID number of the programs you want to terminate, inside the control panel. (pic at bottom)

Then inside your batch file, add this
Code
@echo off
taskkill /F /PID <PID number goes here>
taskkill /F /PID <Second PID number goes here>

So for example, if i wanted to end GyazoStation task, I would use
Code
taskkill /F /PID 10152
. Since the number 10152 represents the task I'm wanting to kill

[Image: SnippingTool_2018-06-08_21-33-53.png]

Hope that helps!


RE: Delete all .exe files in a folder? - b00st3d - Jun 8, 2018

(Jun 7, 2018 09:26 AM)Sir-Teabag Wrote:  Well you could search in the folder for ".exe", then CTRL + A, and then delete all.

Or if you really want to use batch, try

Code
del /Q *.exe
^make sure the batch file is in the folder containing the EXE files.

(Jun 8, 2018 01:37 PM)Sir-Teabag Wrote:  Well whatever is easier. Personally I would manually do it but you can use Batch if you want.

First, find the PID number of the programs you want to terminate, inside the control panel. (pic at bottom)

Then inside your batch file, add this
Code
@echo off
taskkill /F /PID <PID number goes here>
taskkill /F /PID <Second PID number goes here>

So for example, if i wanted to end GyazoStation task, I would use
Code
taskkill /F /PID 10152
. Since the number 10152 represents the task I'm wanting to kill

[Image: SnippingTool_2018-06-08_21-33-53.png]

Hope that helps!

PID changes doesn't it? If I'm correct you're going to want to terminate the process by name instead of PID. I use /f because I'm forceful...I don't know if it actually makes a difference.

Code
taskkill /im processname.exe /f



RE: Delete all .exe files in a folder? - Sir-Teabag - Jun 9, 2018

(Jun 8, 2018 08:24 PM)b00st3d Wrote:  PID changes doesn't it?  If I'm correct you're going to want to terminate the process by name instead of PID.  I use /f because I'm forceful...I don't know if it actually makes a difference.

Code
taskkill /im processname.exe /f

Ah my bad, you're right! Sorry OP, use the process name instead of the PID, like mentioned above. 🤦‍♂ ✌


RE: Delete all .exe files in a folder? - cbdaeeeebc - Jun 10, 2018

(Jun 7, 2018 09:26 AM)Sir-Teabag Wrote:  Well you could search in the folder for ".exe", then CTRL + A, and then delete all.

Or if you really want to use batch, try

Code
del /Q *.exe
^make sure the batch file is in the folder containing the EXE files.

t y , . .