I need to create a command that allows me to insert a check of a text file for a very specific symbol (’) and I am having trouble. It is a single quotation mark and it occasionally is found on some folders that need to be zipped and when my batch zipper encounters the folder with the symbol in it's name, it just starts having a lot of problems and creates weird files. I am not going into a lot of detail, but I just need a way to (in plain terms) check if a text file contains the symbol (’) and if it does, send the script to an error line (just something to indicate the symbol was found, like "echo error found"). And if not, then just send it to the rest of the script...
Like FINDSTR "’" dirlist.txt if found goto err else goto resume I know that is very incorrect but you get the idea.
Here is what I have so far and I still have made no progress getting it to work:
findstr /i /c:"’" C:\ACFZ\FORZIP\dirlist.txt >2 if %errorlevel% EQU 0 (goto LABEL0) else (goto LABEL1) :LABEL0 msg %username& "An invalid symbol has been found. Remove any single quotation marks (’) from the folder names and try again. If unsure, simply remove anything that looks like an apostrophe." pause goto ERROR :LABEL1 echo No errors found, continuing pause goto ZIPSTART :ERROR echo an error was found, exiting... pause goto EXIT
It always ends up saying no errors, even though the file has the symbol in it.
Here is the text file I need to search (dirlist)
2082708 Amboy Bank 2082712 Cavender’s 2082736 Elizabeth Board of Education 2082763 Tri-Valley Developmental Services LLC 2082773 Vector Management
OK, so I finally got it working right... Thanks to Harvey, I used the method of outputting any results to a separate file, and then checking that file for contents. Which actually works great, because if it finds an issue, it will show you the full name of the problem folder(s) so you can easily fix it.
Here is the snippet of the working part:
findstr "'" C:\ACFZ\FORZIP\dirlist.txt > error.txt findstr "." error.txt >nul IF %ERRORLEVEL% EQU 0 GOTO POPUP IF %ERRORLEVEL% EQU 1 GOTO ALLCLEAR
and here it is with a bit more detail:
CD C:\ACFZ\FORZIP DIR /AD /B /ON >dirlist.txt Echo Checking for errors in folder names... ping -n 3 localhost >nul REM that is not an apostrophe! findstr "'" C:\ACFZ\FORZIP\dirlist.txt > error.txt findstr "." error.txt >nul IF %ERRORLEVEL% EQU 0 GOTO POPUP IF %ERRORLEVEL% EQU 1 GOTO ALLCLEAR REM Errorlevel 0= Something found, 1= nothing found :POPUP color cf msg %username% "An invalid symbol has been found. Remove any single quotation marks (’) from the folder names and try again. If unsure, simply remove anything that looks like an apostrophe." goto ERROR :ALLCLEAR echo No errors found, continuing... ping -n 3 localhost >nul ping -n 3 localhost >nul goto ZIPSTART :ERROR echo An error was found in the following folder name(s) below:^ findstr "." error.txt echo. Echo Remove any symbols from the above folder name(s) echo within your completed folder and try again. Echo This program will now exit. pause goto EXIT :ZIPSTART REM Zip contents of each directory for /f "tokens=*" %%a in (dirlist.txt) do ( CD "%%a" wzzip "C:\ACFZ\ZIPPED\%%a.zip" CD.. )
Glad I was able to fix this. I guess WinZip goes really crazy from that quotation mark. The reason I needed this was I wrote this batch script (there is more to it than what I have above, as this was the part I needed to work on) to automate the zipping and backup process at my work, so that the folders for the month's jobs are zipped up and then copied onto the server for archive. It was a pain to manually do it, so with this I can just do it all in one step.
Oh and yeah the errorlevel issue was I did not have it entered correctly. I did not space them over to the right.
Thanks to all who helped.