I want to create a small batch script for my " Send to " menu that deletes certain files:
I have a lot of files named in this convention: foo.xxx, foo.jpg, bar.xxx and bar.jpg
. I want to delete .xxx
files where there is a corresponding .jpg
file recursively for all nested folders below the level from where I call this script.
Based on this post I came up with the following:
@ echo off
pushd "%~1"
for /R %%f in (*.jpg) do echo "%%f"
This at least lists the .jpg
files it seems but I get an error message that reads like this:
"UNC-Pfade werden nicht unterstützt. Stattdessen wird das Windows-Verzeichnis als aktuelles Verzeichnis gesetzt."
I found a post which shows how to delete files recursively but I do not really understand how to combine the two solutions to delete only those .xxx
files for which I found a .jpg
. Furthermore it would be nice if there where some sanity check that checks if there really is a .xxx
file with the current name, sometimes there are .jpg
files in these folders that have no corresponding .xxx
file.
It seems I can remove by file extension like this:
@ echo off
pushd "%~1"
for /R %%f in (*.jpg) do echo "%%~nf"
But now I have no complete path to delete the wanted files? Is this correct so far? Thank you in advance!
Solution:
@ echo off
pushd "%~1"
for /R %%I in (*.jpg) do del "%%~dpnI.vgd"
popd
See comments for all contributions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.