So, I'm programming a game, but the compiler I use is written as a Windows batch file. I'm using Windows 10 as my operating system. In my game files, I have one folder with images, and another folder with upscaled versions of those images that have the same file name and extension. What I want to do is have the batch file go through all the images in the directory with the upscaled images, and check if a file with the same name and extension exists in the directory with the original images. If it doesn't exist in the original directory, it will delete it from the upscaled directory.
Asked
Active
Viewed 1,424 times
-1
-
Fine. And what is your _specific_ question? Please learn [how to ask](http://stackoverflow.com/help/how.to-ask)! We don't write code for you for free. – aschipfl Jul 12 '16 at 14:47
-
@aschipfl The question is about what kind of loop should I use, I can't really figure out the proper way to do this. – Eduardo Perez Jul 12 '16 at 15:05
-
What about a `for` loop (open a new command prompt window, type `for /?` and read the help very carefully)? – aschipfl Jul 12 '16 at 15:09
-
@aschipfl Yep, got it working. I added an answer. – Eduardo Perez Jul 12 '16 at 15:45
1 Answers
0
I got it working using an answer over here: Batch Extract path and filename from a variable
All I had to do was extract the file name and extension, and then run all the files in one folder through the loop, checking if the file exists in the other folder.
Here is my code:
for %%i in (%folder1%\*.png) DO (
if not exist "%folder2%\%%~nxi" ECHO %%~nxi
)
If you actually want to delete the files, change ECHO
to del /q
, be warned you will lose files, so make sure you have backups.

Community
- 1
- 1

Eduardo Perez
- 503
- 7
- 22