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.
Related
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.
I'd like to run a program which takes an input file and an output file with a parameter.
I'd like to do so, for every file in my folder.
I tried with a for loop and forfiles, but I can't manage to make it work.
The syntax for the application is:
gdcmconv [options] file-in file-out
Here is my code:
set INPUTPATH="C:\input\"
set OUTPUTPATH="C:\Output\"
#echo on
for /D %%G in (%INPUTPATH%) do (
echo '%%~nxG'
"C:\Program Files\GDCM 2.8\bin\gdcmconv.exe" -X %%~nxG %%~nxG)
also tried:
forfiles /p %INPUTPATH% /s /m *.bat /c "cmd /c "C:\Program Files\GDCM 2.8\bin\gdcmconv.exe //X %INPUTPATH%#file %OUTPUTPATH%#file"
It seems it does not get the #file or %%~nxG as input or output
The solution you request is as follows:
#echo off
set INPUTPATH="C:\input\"
set OUTPUTPATH="C:\Output\"
for /R "%INPUTPATH%" %%A IN (*.bat) do (
rem echo '%%~nxG'
"C:\Program Files\GDCM 2.8\bin\gdcmconv.exe" -X %%~nxG %%~nxG
)
for /R loops through all subfolders.
The rest of the code searches in these subfolders for .bat files, and process them as you requested.
I have created a batch file that will run on an FTP server. There is a camera that saves files in the format xxxxNG.txt and xxxxOK.txt in C:\images\0000. The script I wrote renames the files with the current time and date and moves them to an OK or NG folder elsewhere depending on the original file name.
This works well, however if there are multiple images to process at once, the program names them all the same thing and overwrites until there aren't any more, leaving only the last one.
Here's what I have so far:
rem This is a simple script to move images from the FTP save location to the
backup location (here)
echo off
cls
:again
#echo off
cls
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "dateandtime=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
echo The current time is: %dateandtime%
echo.
echo Moving new files...
rem if exist %dateandtime%*.txt (
for /r "C:\test\Images" %%x in (*OK.txt) do move "%%x" C:\test\OK\" "%dateandtime%_OK.txt"
for /r "C:\test\Images" %%x in (*NG.txt) do move "%%x" C:\test\NG\" "%dateandtime%_NG.txt"
echo New files have been renamed and moved.
echo.
echo Checking for old files...
forfiles -p "C:\test\OK" -s -m *.* -d -1 -c "cmd /c del /Q #path"
forfiles -p "C:\test\NG" -s -m *.* -d -1 -c "cmd /c del /Q #path"
echo Files older than 5 years have been deleted.
echo.
timeout /t 1 /nobreak
goto again
echo done
How do I get it to name files processed at the same time to not overwrite and have different names? I tried a method checking if the file already exists, but I'm not sure how to modify the for /r "C:\test\Images" %%x in (*OK.txt) do move "%%x" C:\test\OK\" "%dateandtime%_OK.txt" line to accommodate this. I'm trying something like
for /r "C:\test\Images" %%x in (*OK.txt) do move "%%x" C:\test\OK\" "%dateandtime%-%foo%_OK.txt"
but the %foo% breaks it. I thought I understood foo as the iteration of the for loop. is there an equivalent in the do loop?
Thank you in advance.
IMHO, the easiest way to fix your current issue is to use the original file name and append the time stamp to the original file name.
for /r "C:\test\Images" %%G in (*OK.txt) do move "%%G" "C:\test\OK\%%~nG-%dateandtime%%%~xG"
I use upper case letters for my FOR meta-variable so that it does not cause any confusion as to what command modifier is being used.
So if your input file names are:
1234OK.txt
7890OK.txt
They will be moved and renamed to:
1234OK-20180314104211.txt
7890OK-20180314104211.txt
I am using .bat script to access sftp and download file. The ftp folder consist of a lot of file which can be uniquely identify by the file name in format YYYYMMDD. eg: 20180307.csv, 20180306.csv etc. Currently I am using mget to get all the file, then at later filter it locally. How can I modify the script to get the file on today only?
This is my .bat script.
D:
CD\myTargetFolder
psftp user#sftp.myftpserver.com -pw password -b mySftpScript.ftp
exit
This is my ftp script.
cd /myFTPSourceFolder
mget *.csv
bye
Thank you.
If you don't mind dynamically creating the ftp script then perhaps your .bat script could look like this:
#Echo Off
CD /D D:\myTargetFolder 2>Nul || Exit /B
Set "csv="
For /F "Tokens=1-3 Delims=/ " %%A In ('RoboCopy /NJH /L "\|" Null'
) Do If Not Defined csv Set "csv=%%A%%B%%C.csv"
( Echo cd /myFTPSourceFolder
Echo mget %csv%
Echo bye)>"mySftpScript.ftp"
psftp user#sftp.myftpserver.com -pw password -b mySftpScript.ftp
::Del "mySftpScript.ftp"
I've commented out the last line, remove the :: from it if you wish to delete the dynamically created ftp script.
Edit
To get yesterday's date csv then something like this, leveraging PowerShell, would be my recommendation:
#Echo Off
CD /D D:\myTargetFolder 2>Nul || Exit /B
Set "csv="
For /F UseBackQ %%A In (
`PowerShell "(Get-Date).AddDays(-1).ToString('yyyMMdd')"`
) Do Set "csv=%%A.csv"
( Echo cd /myFTPSourceFolder
Echo mget %csv%
Echo bye)>"mySftpScript.ftp"
psftp user#sftp.myftpserver.com -pw password -b mySftpScript.ftp
::Del "mySftpScript.ftp"
so I'm writing a script to scan mkv files and downconvert any 1080p files to 720p. I'm currently running through each file using a "for /r" loop to include subfolders. Is there a way I can recreate the subfolders into the output destination?
Here's what I have so far (p.s. It's my first script):
#echo off
set mediainfo="%~dp0MediaInfo.exe"
set result="%~dp0width.txt"
set handbrake="%~dp0HandBrakeCLI.exe"
SETLOCAL ENABLEDELAYEDEXPANSION
Set /P source=Enter source path:
Set /P output=Enter destination for converted files:
if %output:~-1%==\ set output=%output:~0,-1%
if not exist %output% mkdir %output%
for /R %source% %%j in (*.mkv) do (
Echo Filepath is: %%j
%mediainfo% --Inform=Video;%%Width%% "%%j" > %result%
set /P width=<%result%
del %result%
echo Width is: !width!
if !width! == 1920 (%handbrake% -i "%%j" -o "%output%\%%~xnj" -f mkv -e x264 -q 20 --vfr -a 1,1 -E av_aac,ac3 -B 192 -w 1280 --keep-display-aspect -x level=4.1:vbv-bufsize=78125:vbv-maxrate=62500) else (echo No need to transcode.)
)
Now if I have a structure like:
TV Show\Season 1
\Season 2
\Season 3
I would like the source dir to be "TV Show" and the output to keep the files in the same folder structure. Would this be doable?
EDIT: I updated the code a bit, added an if stated to compare %%~nxq (Season X) minus the last 2 characters to the word "Season" to determine if the working folder was inside a season subfolder. Only problem is if it's "Season 10" then the if comparison will read "Season ". Haven't tested it out and I'm not sure if there is a way to use wildcards in an if statement. Here's the updated code:
#echo off
set mediainfo="%~dp0MediaInfo.exe"
set result="%~dp0width.txt"
set handbrake="%~dp0HandBrakeCLI.exe"
SETLOCAL ENABLEDELAYEDEXPANSION
Set /P source=Enter source path:
echo Source path is: %source%
Set /P a=Enter destination for converted files:
set output=%a:"=%
if not %output:~-1%==\ (set output="%output%\") else (set output="%output%")
echo Destinition path is: %output%
if not exist %output% mkdir %output%
set dest=%output%
for /R %source% %%j in (*.mkv) do (
Echo Filepath is: %%j
for %%q in ("%%~dpj.") do (
set sea=%%~nxq
if "!sea:~0,-2!"=="Season" (
set dest="%output:"=%%%~nxq\%%~xnj"
set seafold="%output:"=%%%~nxq"
if not exist !seafold! mkdir !seafold!
) else (
set dest="%output:"=%%%~xnj"
)
echo Output Path is: !dest!
)
%mediainfo% --Inform=Video;%%Width%% "%%j" > %result%
set /P width=<%result%
del %result%
echo Width is: !width!
if !width! == 1920 (%handbrake% -i "%%j" -o !dest! -f mkv -e x264 -q 20 --vfr -a 1,1 -E av_aac,ac3 -B 192 -w 1280 --keep-display-aspect -x level=4.1:vbv-bufsize=78125:vbv-maxrate=62500) else (echo No need to transcode.)
)
Certainly.
for %%q in ("%%~dpj.") do echo %%~nxq
should provide you with a clue, given that you've worked out your first batch so far...
(~dpj gives you the drive/path of %%j; then use a quirk to extract the name and extension of the last element of the directoryname)