Script should run in recursive mode, find DAV files and start DAV to JPG conversions using FFMPEG. The script is working, identifying files in folders and starting conversions when DAV files exist, but is ignoring some DAV files.
When I put these DAV files back in the folder it converts correctly.
What could be wrong?
I thought it might be the speed of the process, since the files are being generated in the folder, the script must wait for the file to be closed and complete to act. I tried to delay the conversion process by 15 seconds using a PING, but it still skips some files.
cd E:\VM01\1002
MD "E:\COLETA SNAPSHOT\SNAPSHOT 1002"
MD "E:\COLETA SNAPSHOT\PROCESSED 1002"
:LOOP01
PING 1.1.1.1 -n 10 -w 6000 >NUL
For /R %%G in (*.Dav) do IF NOT EXIST "%%G" GOTO SKIP01
:LOOP02
PING 1.1.1.1 -n 10 -w 6000 >NUL
For /R %%G in (*.Dav) do IF EXIST "%%G" GOTO SKIP02
REM ALL THIS WILL BE DONE IF THE DAV FILE EXISTS
:
:
:SKIP01
REM 6 SECONDS OF DELAY ...
PING 1.1.1.1 -n 10 -w 6000 >NUL
GOTO LOOP01
:
:
:SKIP02
REM START CONVERSION
PING 1.1.1.1 -n 10 -w 15000 >NUL
For /R %%G in (*.Dav) do IF EXIST "%%G" ffmpeg -i "%%G" -r 0.2 -bt 20M -s 480x300 "%%~nG"%%06d.jpg
for /r %%G in (*.Dav) do Move "%%G" "E:\COLETA SNAPSHOT\PROCESSED 1002"
Move "*.jpg" "E:\COLETA SNAPSHOT\SNAPSHOT 1002"
PING 1.1.1.1 -n 10 -w 3000 >NUL
)
GOTO LOOP01
I have rewritten your script to work in the manner I think your posted example is supposed to, and subject to you running it on windows-vista or newer:
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
Set "DavTree=E:\VM01\1002"
Set "DavDone=E:\COLETA SNAPSHOT\PROCESSED 1002"
Set "JpgDone=E:\COLETA SNAPSHOT\SNAPSHOT 1002"
CD /D "%DavTree%" || "%__AppDir__%timeout.exe" /T 3 1>NUL & GoTo :EOF
If Not Exist "%DavDone%\" MD "%DavDone%" || "%__AppDir__%timeout.exe" /T 3 1>NUL & GoTo :EOF
If Not Exist "%JpgDone%\" MD "%JpgDone%" || "%__AppDir__%timeout.exe" /T 3 1>NUL & GoTo :EOF
:ProcessDavs
"%__AppDir__%where.exe" /Q /R . *.Dav
If ErrorLevel 1 "%__AppDir__%timeout.exe" /T 6 1>NUL & GoTo ProcessDavs
For /F "Delims=" %%# In ('Dir /B /S /A:-D-S-L /O:D /T:W *.Dav') Do (
"%__AppDir__%timeout.exe" /T 3 1>NUL
"F:\ull\PathTo\FFmpeg.exe" -i "%%#" -r 0.2 -bt 20M -s 480x300 "%%~n#%%06d.jpg"
If Not ErrorLevel 1 (Move /Y "%%#" "%DavDone%" 1>NUL
Move /Y "%%~n#%%06d.jpg" "%JpgDone%" 1>NUL))
GoTo ProcessDavs
Please note on line 15, I have used "F:\ull\PathTo\FFmpeg.exe", please adjust this to the correct location. If located in %PATH% or E:\VM01\1002, you can edit it to just FFmpeg.exe, if your %PATHEXT% variable is unmodified, you can also remove the .exe, (I'm not recommending either). The issue I highlighted in the comments, does not form part of this answer, however, I have arranged the command to recurse the directories so that it picks up the least recently written .dav file first. This may give additional time for any files still being written to complete before you process them. You can also adjust the 6 second timeout on line 12 and 3 second timeout on line 14 as necessary, if the issue persists.
Related
In a batch script I'm running sqlcmd in a loop that goes through a folder of SQL scripts. I would like to be able to pass the script/output file currently being worked on to a label exterior to the loop in the case of an error.
Here's sample code:
#echo off
#setlocal enabledelayedexpansion
SET _INSTANCE=someinstance
SET _DATABASE=somedatabase
SET "_SCRIPTFOLDER=D:\Scripts for Testing"
SET "_OUTPUTFOLDER=D:\Output for Testing"
FOR %%S IN (
"%_SCRIPTFOLDER%\*.sql"
) DO (
SET /P _MSGa=Generating CSV: %%~nS.csv ... <NUL
sqlcmd -b -S %_INSTANCE% -d %_DATABASE% -i "%%~fS" -s "|" -o "%_OUTPUTFOLDER%\%%~nS.csv" -W
IF ERRORLEVEL >= 1 GOTO sqlcomderrorhandling
SET /P _MSGb=file created. Removing header dashes ... <NUL
REM REM Remove the line with dashes below the header
#FINDSTR /r /b /v /c:"-*|" "%_OUTPUTFOLDER%\%%~nS.csv" > "%_OUTPUTFOLDER%"\tmp.txt
IF ERRORLEVEL >= 1 GOTO findstrerrorhandling
XCOPY /Y "%_OUTPUTFOLDER%"\tmp.txt "%_OUTPUTFOLDER%\%%~nS.csv" >NUL
IF ERRORLEVEL >= 1 GOTO copyerrorhandling
ECHO done.
)
DEL /Q /F "%_OUTPUTFOLDER%"\tmp.txt
GOTO done
:sqlcomderrorhandling
ECHO An error occurred while processing the file %%~nS.csv
:done
#pause
The last ECHO just outputs %~nS.csv, not the actual name of the CSV file. Do I need to utilize functions in some way to do what I want to do?
Based on part of rojo's first comment and my own, would this sort of structure not make more sense?
#Echo Off
Set "_INSTANCE=someinstance"
Set "_DATABASE=somedatabase"
Set "_SCRIPTFOLDER=D:\Scripts for Testing"
Set "_OUTPUTFOLDER=D:\Output for Testing"
If Not Exist "%_OUTPUTFOLDER%\" (Echo Output folder doesn't exist
Timeout 3 /NoBreak >Nul
GoTo :EOF)
If Not Exist "%_SCRIPTFOLDER%\*.sql" (Echo Source folder doesn't contain any SQL files
Timeout 3 /NoBreak >Nul
GoTo :EOF)
CD /D "%_SCRIPTFOLDER%" 2>Nul || (Echo Source folder, %_SCRIPTFOLDER%, is not available.
Timeout 3 /NoBreak >Nul
GoTo :EOF)
For %%A In (*.sql) Do (
Echo Generating CSV: %%~nA.csv ...
SQLCmd -b -S %_INSTANCE% -d %_DATABASE% -i "%%A" -s "|" -o "%_OUTPUTFOLDER%\%%~nA.csv" -W 2>Nul && (
Echo File created. Removing header dashes ...
Findstr "[^-|]" "%_OUTPUTFOLDER%\%%~nA.csv">"%_OUTPUTFOLDER%"\%%~nA.tmp" && (
Move /Y "%_OUTPUTFOLDER%"\%%~nA.tmp" "%_OUTPUTFOLDER%\%%~nA.csv">Nul 2>&1 || (
Echo A Move error occurred while moving %%~nA.tmp
Timeout 2 /NoBreak >Nul)) || (Echo A FindStr error occurred while removing header dashes
Timeout 2 /NoBreak >Nul)) || (Echo A SQLCmd error occurred while processing the file %%~nS.csv
Timeout 2 /NoBreak >Nul))
Pause
I would like to ask if anyone has an idea how to send search result to console in single command line but with some specific code before and after the search results output
I need to run program Xconverter that is made to be operated by console, and has parameters:
-s :silent mode (only mode suported yet)
-i [files] : list location of the files in quotes: {-i "a.txt" "b.txt"..}
-t [tool file] : tool file location
-m 5 : conversion style
syntax accepted for example (single command for XConverter):
"C:\XConverter.exe" -s -i "C:\a.pgm" "C:\abc\b.pgm" -t "tool.tlgx" -m 5
but I need about 500 -i [files] to list
so i created search that fill look for those .pgm in tree mode where .bat is located and adds search result (file locations) one after other
my code is working but the only way i made it to work is that i outputed echo result in to extra .bat file and started the file. Is there i way to reprogram my code that it will send these outpust in to single one line command?
echo off
SET mypath=%~dp0
::THIS STARTS PROGRAM
(
echo | set /p="""
echo | set /p="C:\Program Files (x86)\Scm Group\Maestro\XConverter.exe" -s -i "
)>seznam_konvertovanych_suboru.bat
::THIS SEARCHERS FOR PGM FILES AND ADDS PATH OF EACH FILE TO THE LINE
for /f "delims=" %%A in ('forfiles /s /m *.pgm /c "cmd /c echo #relpath"') do (
set "file=%%~A"
setlocal enableDelayedExpansion
echo | set /p="""
echo | set /p="%mypath:~0,-1%\!file:~2!"
echo | set /p="" "
)>>seznam_konvertovanych_suboru.bat
::THIS ADDS SOME EXTRA FILE PATH TO THE LINE OF TOOL FILE, THAT IS NEEDED
(
echo | set /p=-t "Tlgx\def.tlgx" -m 5
)>>seznam_konvertovanych_suboru.bat
seznam_konvertovanych_suboru.bat
This code will output file seznam_konvertovanych_suboru.bat exactly in this format
"C:\XConverter.exe" -s -i "C:\a.pgm" "C:\abc\b.pgm" -t "tool.tlgx" -m 5
Anyone knows how to reprogram this to send that output to console in single line without creating extra file to store that code?
Edited:
What i need is having START_CONVERTING.BAT file that will send to console one command :
"C:\XConverter.exe" -s -i "C:\a.pgm" "C:\abc\b.pgm" -t "tool.tlgx" -m 5
but "C:\a.pgm" "C:\abc\b.pgm" are the search results of all .pgm files in that folder and child folders. So i will copy this START_CONVERTING.BAT anywehere where i store .pgm files. (some of them are in folders and those folders in other folders) so i will just copy STAR_CONVERTING.BAT in major folder that will thake care of all files with all files in child folders.
I will just click START_CONVERTING.BAT and it will convert those .pgm files. (without creating creating any other output to any other .bat file.
SOLVED (code)
#echo off & setlocal enableDelayedExpansion
PushD "%~dp0"
Set "XC=C:\Program Files (x86)\Scm Group\Maestro\XConverter.exe"
Set "TOOLFILE=Tlgx\def.tlgx"
Set "Files="
:: Concatenate all files in one string
for /f "delims=" %%A in ('Dir /B /S *.pgm') do set Files=!Files! "%%~A"
:: command, command line length may be an issue
"%XC%" -s -i%Files% -t "%TOOLFILE%" -m 5
If I understand right this might work
#echo off & setlocal enableDelayedExpansion
PushD "%~dp0"
Set "XC=C:\Program Files (x86)\Scm Group\Maestro\XConverter.exe"
Set "Files="
:: Concatenate all files in one string
for /f "delims=" %%A in ('Dir /B /S *.pgm') do set Files=!Files! "%%~A"
:: store command in batch file, command line length may be an issue
>"seznam_konvertovanych_suboru.bat" Echo "%XC%" -s -i %Files% -t "tool.tlgx" -m 5
try with that batch
Xconverter is for xxl to PGMX
1 set all path for converter
2 creat to do list of xxl files on desktop on this exemple or desktop sub folder!
3 Masetro can't be install as Office PC you must run it on CN PC!
#echo OFF
COLOR F1
TITLE "Convertor XXL to PGMX"
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Converteur Xconverter º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
echo "Stop command with Ctrl+C"
echo.
Echo "Path SET"
TIMEOUT /t 5 >nul
Set todo="%userprofile%\desktop\todo.txt"
Set def="%PROGRAMFILES(x86)%\Scm Group\Maestro\Tlgx\def.tlgx"
Set Compil="%PROGRAMFILES(x86)%\Scm Group\Maestro\Xconverter.exe"
Set desktop="%userprofile%\desktop"
echo "To do list of *.XXL files"
TIMEOUT /T 10 >nul
cd %userprofile%\desktop
dir /a /b /o /s *.xxl > %todo%
echo "Files convert command"
TIMEOUT /T 10 >nul
for /f "delims=" %%a in (%todo%) do %Compil% ^ -s -m 4 ^
-i "%%a" ^
-t %def%
echo "Rapport files"
Timeout /T 10 >nul
cd %desktop%
dir /a /b /o /s *.pgmx > Rapport.txt
Echo "Delete to do list"
TIMEOUT /T 10 >nul
DEL %todo% /F /S /Q >nul
But haven't go detail of Convesion style -m X
if you can replie me detail of -m number it was great!
All the best, and hope this is helpful
D-Alexandre V.
I work at a radio station where we audio log using a program called Skimmer Plus that creates multiple sub directories out of our parent directory "Air Check" and the directory tree looks like this (descending):
Air Check
Year (so right now it would be 2016)
Month (November)
Day (22)
And the .wav files are saved in the Day directory, but there are no files saved in any of the other directories, just in the "Day" directory.
What I am struggling with is first automatically converting the .wav files to .mp3 files. Right now I just use the lame dropper "lamedropXPd3-64.exe", but I also have "lame.exe" downloaded and available to use if that would make it easier. Here is the code I have attempted with the automatic conversion:
#echo off
PushD for %%i in (*.wav) do "\\wideorbit.byui.edu\d\Radio Productions\Air Check\2016\November\22" -V 6 --vbr-old --resample 22.05 "%%i" "%%~ni.mp3" & PopD
pause
And the error message I get is: "The filename, directory name, or volume label syntax is incorrect."
So that is my first issue.
The second issue (deleting the leftover .wav files in order to save space) I'm a lot closer on getting to work. Here is my code:
#echo off
PushD "\\wideorbit.byui.edu\d\Radio Productions\Air Check\2016\November\22" &&(forfiles -m *.wav* -d -0 -c "cmd /c del /s /q #path") & PopD
pause
And that works to delete all the files, but as you can see, it will only affect that day. I want it to work from this point right here:
#echo off
PushD "\\wideorbit.byui.edu\d\Radio Productions\Air Check\" &&(forfiles -m *.wav* -d -0 -c "cmd /c del /s /q #path") & PopD
pause
But when I try and run that, I get the following error message:
"ERROR: no files found with the specified search criteria."
What could I change on both parts of the code to make them fully operable?
(Also, I put the #echo off and pause in there for ease in testing, I will be taking them out when I get a final program together).
Thank you!
To put some decent tips you got together, this batch will by default scan the current day folder for .wav files. But there are optional command line args to scan the whole tree down from Base through /FullScan or current /Year or /Month.
The Lame and Del commands are only Echoed as long as the two echo commands stay in the second last line.
:: Wav2mpg.cmd
#Echo off & SetLocal EnableExtensions EnableDelayedExpansion
Set Lame="X:\Path\to\your\lame.exe"
Set LameOpts= -V 6 --vbr-old --resample 22.05
Set "Base=\\wideorbit.byui.edu\d\Radio Productions\Air Check"
:: Get current Date
For /f "tokens=1-3 delims=.+-" %%A in (
'wmic os get LocalDateTime^|findstr ^^[0-9]'
) do Set _DT=%%A
Set "year=%_DT:~0,4%"&Set "Month=%_DT:~4,2%"&Set "Day=%_DT:~6,2%"
:: Strip leading zero from Month, Get Monthname
set /a Mo=100%Month%%%100
For /f "tokens=%Mo%" %%A in (
'echo/January February March April May June^
July August September October November December'
) do set MonthName=%%A
If /i "%~1" Equ "/FullScan" Goto :Skipover
If /i "%~1" Equ "/Year" Set Base=%Base%\%Year%
If /i "%~1" Equ "/Month" Set Base=%Base%\%Year%\%MonthName%
If /i "%~1" Equ "" Set Base=%Base%\%Year%\%MonthName%\%Day%
:skipover
PushD "%Base%" || (Echo couldn't pushd %Base%&Pause&Exit /B 1)
For /f "delims=" %%A in (
'Dir /B/S/A-D .\*.wav'
) Do Echo %Lame% %LameOpts% "%%~fA" "%%~dpnA.mp3" && Echo Del "%%~fA"
PopD
#echo off
PushD
for %%i in (*.wav) do someexecutablenameherwouldbehelpfulIthink "\\wideorbit.byui.edu\d\Radio Productions\Air Check\2016\November\22" -V 6 --vbr-old --resample 22.05 "%%i" "%%~ni.mp3"
PopD
pause
To convert all .wav files in your directory tree to .mp3 files, you could use the following code:
pushd "\\wideorbit.byui.edu\d\Radio Productions\Air Check" || exit /B 1
for /R %%F in ("*.wav") do (
pushd "%%~dpF" && (
lame -V 6 --vbr-old --resample 22.05 "%%~nxF" "%%~nF.mp3" && (
del "%%~nxF"
)
popd
)
)
popd
To convert .wav files of today (or, more precisely said, those with a modification date of today, without checking the parent directory name), you could use the following code:
pushd "\\wideorbit.byui.edu\d\Radio Productions\Air Check" || exit /B 1
for /F "delims=" %%F in ('
forfiles /S /M "*.wav" /D +0 /C "cmd /C echo #path"
') do (
pushd "%%~dpF" && (
lame -V 6 --vbr-old --resample 22.05 "%%~nxF" "%%~nF.mp3" && (
del "%%~nxF"
)
popd
)
)
popd
Note that for both approaches, successfully converted .wav files are deleted afterwards.
can only recommend "EZ CD Audio Converter", using it for years, being very excited with, for converting (and also deleting in one run). Not expensive, worth every cent. There's a free 30days trial available.
For organizing, moving, tagging I recommend "mp3tag". Can work in batches and tag and move files. Great freeware, but for the full potential you have to learn the syntax.
What I want to be able to do is have the script rename a files that are in use.
Is this possible?
This is my current script.
Thanks in advance!
#echo off
Set FileSource=C:\temp\cleric
Set RemoteDestinationFolder=C:\program files (x86)\cleric
Set InputFile=c:\Test\Computers.txt
Set RemoteDestination=\\%%*\%RemoteDestinationFolder::=$%\
For /F "eol=;" %%* in ('type "%InputFile%"') do (
Ping.exe -n 2 -w 750 %%* | Find/i "TTL=" >Nul&&(
xcopy /Y/q/r/e "%FileSource%" "%RemoteDestination%")||(
echo.%%* "Computer was Not found">>%InputFile%.errors.log)
If Not ErrorLevel 0 echo.%%* "Copy was unsuccesfull">>%InputFile%.errors.log
(Set ErrorLevel=)
)
#echo.
Pause
I have a little problem I'm trying to sort out. I'm recording sound 24/7 and they are split in .wav files that have 2 hour duration. Since .wav files are pretty large I would like to encode them to .mp3. Everything works fine with this script
#echo off
cd path/to/folder
for %%i in (*.wav) do (
lame.exe %%i
del %%i
)
Everything works as it should but there is one problem, I want to check if file is still recording, if that's true then I don't want to encode it. I tried to check file size now and 10 sec later but it gets same value. Here is example
#echo off
cd path/to/folder
for %%i in (*.wav) do (
echo %%~zi
ping -n 10 127.0.0.1 >nul
echo %%~zi
)
output is for example:
444444
and after 10 sec same
444444.
Can someone please tell me how to check file size if it's constantly changing?
Test this on your files.
It will get a filename (sorted alphabetically in NTFS) and test to see if it is locked, and loop if it is - testing every 60 seconds.
When the file is free it will launch lame and then check the next file.
#echo off
cd /d "path/to/folder"
for %%a in (*.wav) do call :next "%%a"
echo done
pause
goto :eof
:next
set "filename=%~1"
:loop
2>nul (call;>>"%filename%") && (
echo "%filename%" is free! & goto :lame
) || (
echo "%filename%" is in use or is read only!
)
timeout /t 60 /nobreak
goto :loop
:lame
lame.exe "%~1"
del "%~1"