BATCH Delete subfile/folder in a directory

Cadapen67 -  
barnabe0057 Posted messages 14431 Registration date   Status Contributeur Last intervention   -
Hello,

I would like to create a script that can delete specific subfiles and folders in multiple directories.

Do you have an example of a script or command lines, please?

Thank you!

Configuration: Windows / Firefox 50.0

3 réponses

barnabe0057 Posted messages 14431 Registration date   Status Contributeur Last intervention   4 929
 
Hello,

To delete a folder and everything it contains:
rmdir /s /q "folder to delete"


To delete specific folders within multiple folders, you need to provide more details.

I assume this is related to the logs of your FTP server.
1
Cadapen67
 
In fact, I would like to delete specific files, for example:
Delete all files containing "Sample" in their name.
Several of these files exist in different folders within the directory.
Do you have any idea?
0
barnabe0057 Posted messages 14431 Registration date   Status Contributeur Last intervention   4 929
 


@echo off

set source="the directory of your choice"

cd %USERPROFILE%

for /f "tokens=*" %%A In ('dir /a-d /b /s %source%\*.* ^| find /i "Sample"') do (del /f "%%A" && echo %%~sA = deletion OK && echo.)

pause

This code searches for "Sample" recursively and deletes the corresponding files.

You must replace the underlined part with the directory of your choice.
0