Have been away from programming for a little while but now finding myself needing to automate some things. Essentially what I would like to do is have the batch file search the local directory for the file named "(U) Password.txt," which consists of 4 lines of string. I want it to search using "findstr" the word, "TEXT," and save skip to the next line capturing that line in a variable to use for the decryption password. The remaining code has been tested and works ok but plenty of room for improvement. Can I use "Skip=1" to capture the line under the market "Text" with findstr to capture the next line?
@ECHO OFF REM version 0.4 :: Get the Current Directory :: SET FolderName=%cd% :: Make the new Encrypted and Unencrypted Folders echo D| md %FolderName%\'Encrypted_Databases' echo D| md %FolderName%\'Unencrypted_Databases' echo D| md %FolderName%\'Difference_Reports' set findtext="TEXT" set findfile="(U) Password.txt" findstr %findtext% %findfile% for /f "delims=" %%a in ('findstr %findtext% %findfile%') do echo %%a :: Decrypt the Databases :: SET /p DB_PASSWORD= %%a IF ["%DB_PASSWORD%"]==[""] ECHO Password not set. & GOTO EXIT SET "DB_FILES=db1.db db2.db db3.db db4.db db5.db db6.db db7.db db8.db db9.db" ECHO Decrypting... SET /a DB_TOTAL_COUNT=0 for %%a in (%DB_FILES%) do ( decryptionSoftware.exe -key "%DB_PASSWORD%" %%a "PRAGMA rekey='';" SET /a DB_TOTAL_COUNT+=1 ) ECHO Done! ECHO. ECHO. ECHO Testing... SET /a DB_COUNT=0 3>nul 2>nul ( for %%b in (%DB_FILES%) do ( for /f "tokens=*" %%I in ('decryptionSoftware.exe %%b "SELECT COUNT(*) FROM SQLITE_MASTER;"') do ( REM The following line will not execute if the SQLite command above fails SET /a DB_COUNT+=1 ) ) ) IF %DB_COUNT%==%DB_TOTAL_COUNT% ECHO Success decrypting! IF %DB_COUNT% LSS %DB_TOTAL_COUNT% ECHO Problem decrypting! ::EXIT :: ECHO. ECHO. : Move Unencrypted Databases from the Root Directory to the newly Created Unencrypted File Structure :: echo F| XCOPY "%folderName%\DatabaseTesting\Unencrypted_Databases\*.db"/Y PAUSE exit