|
Answer» Hi everyone,
I'm new to this forum. Glad I found it...
I was looking all over internet for some help with batch file. I'm pretty new to the batch file writing.
Was wondering if anyone can help me with this question for my computer.
I have a folder and inside this folder there are A LOT of folders.
(e.g C:\pics has folder1, folder2, folder3 ...)
I have a text file with folders that I want to keep in a LIST.
textfile:
folder2838 folder 1211 ... ... ...
I WANTED to make a batch file so that when i run it in C:\pics, it makes a list of all the folders that are not in my text file and output to another text file.
Thank you in advanced for everyones help.
Code: [Select]@echo off>newfile.txt
echo -=for loop with findstr, oneliner but slow=- for /r %%a in (.) do findstr/x /c:"%%~na" scan.txt>nul||echo %%~dpna
echo -=double for loop, longer code but faster=- for /r %%a in (.) do ( SET found= for /f %%B in (scan.txt) do if "%%~na"=="%%b" set found=x if not defined found echo %%~dpna ) ::)>>newfile.txt Thank you for looking into this. I tried doing a test and my newfile.txt output file was empty. Im looking at the code now...Reno,
Did it work for you?
that's why i commented the last line of the code, to output/append to a file, you use the double greater sign (">>"). example: Code: [Select]echo sometexthere>>newfile.txt >>newfile.txt echo sometexthereeither syntax will append "sometexthere" to newfile.txt
the first line @echo off>newfile.txt, mean create/overwrite newfile.txt everytime the batch start.
Code: [Select]@echo off>newfile.txt
echo -=for loop with findstr, oneliner but slow=- for /r %%a in (.) do findstr/x /c:"%%~na" scan.txt>nul||(echo %%~dpna)>>newfile.txt
echo -=double for loop, longer code but faster=- for /r %%a in (.) do ( set found= for /f %%b in (scan.txt) do if "%%~na"=="%%b" set found=x if not defined found echo %%~dpna )>>newfile.txt
there is two methods i can think of ATM, so after you test it out, you can pick one of the method to your preference.
|