I am trying to convert a PDF to a TIFF file for OCR with Tesseract. As of now, because I am running on Windows, I am trying to write the conversion as a batch file. This is what I have so far:
#echo off
:start
SETLOCAL EnableDelayedExpansion
SET IMCONV="C:\Program Files\ImageMagick\convert.exe"
set /p INPUTF=Input file(enter done if done)?
if %INPUTF%==done goto end
set /p OUTPUTF=Output file?
%IMCONV% -density 300 %INPUTF% -depth 8 %OUTPUTF%
goto start
:end
When I run this I get convert.exe:UnableToOpenBlob and that there is no file in directory #error/blob.c/OpenBlob/2695. Any idea what's wrong?
After taking the advice from Mark Setchell the above problem has been fixed however now I receive the error convert.exe: UnableToOpenConfigureFile 'delegates.xml' #warning/configure.c/GetConfigureOptions/706
Related
I believe a windows update broke my .bat file.
What this .bat file is supposed to do is update files within the folder with a date and time using nircmd.exe.
All file names start with mmddyy for reference.
Here is the .bat file code.
REM #echo on
REM setlocal enabledelayedexpansion
FOR /R C:\Users\USERNAME\Desktop\optimize %%F in (*.*) DO call :Setfiletime %%F
goto End
:Setfiletime
SET FNAME=%~n1
echo %FNAME%
SET MM=%FNAME:~0,2%
SET DD=%FNAME:~2,2%
SET YY=%FNAME:~4,2%
nircmd.exe setfiletime %1 "%DD%-%MM%-20%YY% 18:00:00" "%DD%-%MM%-20%YY%18:00:00"
:goto :eof
:End
REM endlocal
The output now shows each line before :Setfiletime, then ends with REM.
Why is this batch file no longer working and what would I need to do to fix it?
EDIT: Fixed - file was in the wrong location. The simplest solution was the best answer.
So I'm trying to setup an easy way of starting videos with a bat file, and having that run Mediainfo first to get the length of the video so it can then stop vlc or whatever else when it's done playing.
Complete name : C:\Users\Tyler\Desktop\Psych s05e11.mp4
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/avc1/mp41)
File size : 116 MiB
Duration : 42 min 36 s
Overall bit rate : 382 kb/s
Writing application : Lavf55.13.102
That's the output from mediainfo I got in a txt file, I'm trying to just pull the 42 and the 36 from the duration bit and use it in another command. I should also add that these numbers have to be used separately. Thanks!
Edit: Thanks for replying everyone love the help;
Here's what I'm trying to run now:
mediainfo.lnk --Language=raw --Output=General;%Duration% "C:\Users\Tyler\Desktop\Psych s05e11.mp4"
and the output is:
2556249
Now I need a way to take the first four digits and use them in a another command, somehow make 2556 a variable?
If you need the duration, use e.g. this command:
mediainfo "--Output=General;%Duration%" YourFileName.ext
In a general way, when you think to some automation, prefer to use e.g.:
mediainfo -f --Language=raw YourFileName.ext
and select the lines which better fits your need, avoid fields with "/String" because they are intended only for display (not for automation).
Jérôme, developer of MediaInfo.
Okay here's what I did finally, thanks for all the help!
C:\mediainfo\MediaInfo.exe --Language=raw --Output=General;%%Duration%% "C:\Users\Tyler\Desktop\Psych_s05e11.mp4" >out.txt
set /p $Duration= <out.txt
set $Duration=%$Duration:~0,4%
echo Result = %$Duration%
del out.txt
pause
and the output is:
C:\mediainfo\MediaInfo.exe --Language=raw --Output=General;%Duration% "C:\Users\Tyler\Desktop\Psych_s05e11.mp4" >out.txt
set /p $Duration= <out.txt
set $Duration=2556
echo Result = 2556
Result = 2556
del out.txt
pause
Press any key to continue . . .
took #echo off outta there so you could see it all
Using FOR /F
#echo off
for /f "delims=" %%a in ('mediainfo "--Output=General;%%Duration%%" "C:\Users\Tyler\Desktop\Psych\s05e11.mp4"') do set $Duration=%%a
Echo %$Duration%
Using a temporary file
#echo off
mediainfo.exe --Language=raw --Output=General;%%Duration%% "C:\Users\Tyler\Desktop\Psych s05e11.mp4" >out.txt
set /p $Duration= <out.txt
set $Duration=%$Duration:~0,4%
echo Result = %$Duration%
del out.txt
Another way using #Jérôme Martinez [raw -output] idea.
Without temporary file, using findstr :
#echo off
for /f "tokens=2 delims=:" %%a in ('mediainfo -f --Language=raw "C:\Users\Tyler\Desktop\Psych s05e11.mp4" ^| findstr /i "duration"') do (
set $Duration=%%a
goto:next
)
:next
set $Duration=%$Duration:~1,4%
echo %$Duration%
How do I get a Batch file to store data? I've tried using Text files and Dat files but no luck. Could anyone help me out?
I tried this for storing a name:
echo %name% >name.txt
but I'm finding it hard making it extract the name data and printing it in a batch file.
Another way is to save the data like this :
#echo off
set "name=Jaden"
>name.txt echo name=%name%
And to get the value again. Just evaluate the line(s) in name.txt
like this :
#echo off
for /f "delims=" %%a in (name.txt) do set %%a
echo name --^> %name%
First set the value and then if you echo to a file redirect, it will send the content value to a file.
set name=Jaden
echo %name% > name.txt
then it will work.
Just use set /p name=<name.txt
I am still working on a converter for .m3u playlist files that ports them from a Windows Media Player generated format into a format that gets accepted by the Teamspeak 3 plugin "Soundboard".
The main converter is finished now and I encountered a last problem:
When writing the new code with a Batch script it gets saved into an ANSI encoded file using echo a-lot-of-text-and-code >> 3.txt and it seems like the plugin can only open UTF-8 encoded files.
Is there any way to change the encoding of 3.txt from ANSI to UTF-8 with Batch only?
Regards, Joe
It took a bit of experimentation, but I successfully tweaked Simon Sheppard's UCS-2 encode method to encode a file as UTF-8 with batch.
#echo off
setlocal
:: utf8.bat infile outfile
:: convert infile to utf8 and save as outfile
if not exist "%~1" goto usage
if "%~2"=="" goto usage
set "infile=%~f1"
set "outfile=%~f2"
:: store current console codepage to var
for /f "tokens=2 delims=:" %%I in ('chcp') do set "_codepage=%%I"
:: temporarily change console codepage to UTF-8
>NUL chcp 65001
:: set byte order mark for outfile
>"%outfile%" set /p "=" <NUL
:: dump infile to outfile encoded as UTF-8
>>"%outfile%" type "%infile%"
:: restore console to original codepage
>NUL chcp %_codepage%
goto :EOF
:usage
echo Usage: %~nx0 infile outfile
This script itself needs to be saved in ANSI encoding, though.
I have a txt file naemd as (settings.txt )which has content
SET BACKUP_DRIVE=E:\
SET BACKUP_DIRECTORY=BACKUP\
SET HOURLY_DIRECTORY=HOURLY\
SET INPUT_DIRECTORY=D:\MySQL\Data\CDR\.
I have a bat file where I want to use these variables for prepare backup path
SET BACKUP_PATH=%BACKUP_DRIVE%%BACKUP_DIRECTORY%%HOURLY_DIRECTORY%%CURRENT_HOUR%\
But I am not getting prepared path.
I have tried
type settings.txt in the bat file
It is printing content of setting file but not implementing it..showing echo is off..
if I do echo on then some prob also.
Please tell me how to use these variables
Thanks
Try this:
#echo off&setlocal
:: set CURRENT_HOUR for testing
set "CURRENT_HOUR=03"
for /f "delims=" %%i in (settings.txt) do %%i
SET "BACKUP_PATH=%BACKUP_DRIVE%%BACKUP_DIRECTORY%%HOURLY_DIRECTORY%%CURRENT_HOUR%\"
echo %BACKUP_PATH%
Output is:
E:\BACKUP\HOURLY\03\