iremenerys
iremenerys

Reputation: 17

How to write a batch file to delete multiple specific files from different paths?

Each time before I start debugging, I need to delete some specific files from different paths. It's a tiresome process as I do it like a million times in a day. So I want to write a batch file that deletes all those at once without prompting.

The first path is

C:\Users\irem\AppData\Roaming\JDeveloper\systemx\DD\servers\DefaultServer\tmp\

I want everything under this temp folder gone. Without the temp folder itself, of course.

The second path is

C:\Users\irem\AppData\Roaming\JDeveloper\systemx\o.j2ee\drs\

I again want everything under this drs folder gone. Again without the drs folder itself, of course.

The third path is

C:\Users\irem\AppData\Roaming\JDeveloper\systemx\

This time I want to delete only the files with .lok extension under the systemx folder.

I tried to write something like this:

del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\DD\servers\DefaultServer\tmp\*.*?" /s
& del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\o.j2ee\drs\*.*?" /s
& del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\*.lok"

However it doesn't meet my expectations, it doesn't work.

I appreciate all the help. Thank you very much.

Upvotes: 0

Views: 2054

Answers (1)

Compo
Compo

Reputation: 38604

Perhaps something like this would do what you want:

@Echo Off
Set "srcPath=%AppData%\JDeveloper\systemx"
Set "tmpPath=DD\servers\DefaultServer\tmp"
Set "drsPath=o.j2ee\drs"
CD /D "%srcPath%" 2>Nul || Exit /B
Del /F /Q /A *.lok
For /D %%A In ("%tmpPath%\*" "%drsPath%\*") Do (RD /S /Q "%%A"
    Del /F /Q /A "%%A\*.*")

I have used the paths you provided in your question, if those have changed, you can alter them by editing lines 2, 3 and 4 as necessary.

Upvotes: 0

Related Questions