|
Компьютерный форум OSzone.net » Программирование, базы данных и автоматизация действий » Скриптовые языки администрирования Windows » CMD/BAT - [решено] Помогите организовать циклическую обработку файлов |
|
CMD/BAT - [решено] Помогите организовать циклическую обработку файлов
|
Новый участник Сообщения: 9 |
привет друзья! помогите мне организовать обработку файлов, которые указываю в переменных %file1%-%file40% в виде цикала .. ну знаете как в PHP есть цикл FOR со счетчиком и прочими атрибутами и он перебирает все значения эллементов массива и выполняет над ними те операции что вам нужно..
помогите плиз вобщем вот мой код.. он очень грамоздкий.. надо в цикл это все дело заключить,чтобы циклически обрабатывать все 40 файлов, что указаны в переменных file1-file40
@echo off setlocal enabledelayedexpansion set ext=avi set bit_rate=133K set dir_vid_scr=C:\Users\yura\Downloads\Video\ set file1=video1 set file2=video2 set file3=video3 set file4=video4 set file5=video5 set file6=video6 set file7=video7 set file8=video8 set file9=video9 set file10=video01 set file11=video11 set file12=video12 set file13=video13 set file14=video14 set file15=video15 set file16=video16 set file17=video17 set file18=video18 set file19=video19 set file20=video20 set file21=video21 set file22=video22 set file23=video23 set file24=video24 set file25=video25 set file26=video26 set file27=video27 set file28=video28 set file29=video29 set file30=video30 set file31=video31 set file32=video32 set file33=video33 set file34=video34 set file35=video35 set file36=video36 set file37=video37 set file38=video38 set file39=video39 set file40=video40 cd "%dir_vid_scr%" if /i exist "%file1%.%ext%" (goto :recompress_file1) else ( echo "%file1%.%ext%" NOT EXISTS! goto :if_after_file1_exists ) :if_after_file1_exists if /i exist "%file2%.%ext%" (goto :recompress_file2) else ( echo "%file2%.%ext%" NOT EXISTS! goto :if_after_file2_exists ) :if_after_file2_exists if /i exist "%file3%.%ext%" (goto :recompress_file3) else ( echo "%file3%.%ext%" NOT EXISTS! goto :if_after_file3_exists ) :if_after_file3_exists if /i exist "%file4%.%ext%" (goto :recompress_file4) else ( echo "%file4%.%ext%" NOT EXISTS! goto :if_after_file4_exists ) :if_after_file4_exists if /i exist "%file5%.%ext%" (goto :recompress_file5) else ( echo "%file5%.%ext%" NOT EXISTS! goto :if_after_file5_exists ) :if_after_file5_exists if /i exist "%file6%.%ext%" (goto :recompress_file6) else ( echo "%file6%.%ext%" NOT EXISTS! goto :if_after_file6_exists ) :if_after_file6_exists if /i exist "%file7%.%ext%" (goto :recompress_file7) else ( echo "%file7%.%ext%" NOT EXISTS! goto :if_after_file7_exists ) :if_after_file7_exists if /i exist "%file8%.%ext%" (goto :recompress_file8) else ( echo "%file8%.%ext%" NOT EXISTS! и т.д до 40 ........................ ......................... ......................... :if_after_file37_exists if /i exist "%file38%.%ext%" (goto :recompress_file38) else ( echo "%file38%.%ext%" NOT EXISTS! goto :if_after_file38_exists ) :if_after_file38_exists if /i exist "%file39%.%ext%" (goto :recompress_file39) else ( echo "%file39%.%ext%" NOT EXISTS! goto :if_after_file39_exists ) :if_after_file39_exists if /i exist "%file40%.%ext%" (goto :recompress_file40) else ( echo "%file40%.%ext%" NOT EXISTS! goto :exit ) :recompress_file1 echo Processing file1 '%file1%.%ext%' in folder '%dir_vid_scr%' echo. ffmpeg -loglevel error -i %file1%.%ext% -c:v libx264 -c:a copy -b:v %bit_rate% -maxrate %bit_rate% -bufsize %bit_rate% %file1%_rcm.%ext% echo Checking video duration for '%file1%.%ext%' echo. for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file1%.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_orig_file1=%%i for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file1%_rcm.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_rcm_file1=%%i echo original file duration: %dur_orig_file1% sec. echo recompressed file duration: %dur_rcm_file1% sec. if %dur_orig_file1% == %dur_rcm_file1% ( echo GREAT. files have same duration. Will remove original video '%file1%.%ext%' del "%file1%.%ext%" echo removed ok. ) echo ---------------------------------------------------------------- echo. goto :if_after_file1_exists :recompress_file2 echo Processing file2 '%file2%.%ext%' in folder '%dir_vid_scr%' echo. ffmpeg -loglevel error -i %file2%.%ext% -c:v libx264 -c:a copy -b:v %bit_rate% -maxrate %bit_rate% -bufsize %bit_rate% %file2%_rcm.%ext% echo Checking video duration for '%file2%.%ext%' echo. for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file2%.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_orig_file2=%%i for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file2%_rcm.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_rcm_file2=%%i echo original file duration: %dur_orig_file2% sec. echo recompressed file duration: %dur_rcm_file2% sec. if %dur_orig_file2% == %dur_rcm_file2% ( echo GREAT. files have same duration. Will remove original video '%file2%.%ext%' del "%file2%.%ext%" echo removed ok. ) echo ---------------------------------------------------------------- echo. goto :if_after_file2_exists :recompress_file3 echo Processing file3 '%file3%.%ext%' in folder '%dir_vid_scr%' echo. ffmpeg -loglevel error -i %file3%.%ext% -c:v libx264 -c:a copy -b:v %bit_rate% -maxrate %bit_rate% -bufsize %bit_rate% %file3%_rcm.%ext% echo Checking video duration for '%file3%.%ext%' echo. for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file3%.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_orig_file3=%%i for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file3%_rcm.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_rcm_file3=%%i echo original file duration: %dur_orig_file3% sec. echo recompressed file duration: %dur_rcm_file3% sec. if %dur_orig_file3% == %dur_rcm_file3% ( echo GREAT. files have same duration. Will remove original video '%file3%.%ext%' del "%file3%.%ext%" echo removed ok. ) echo ---------------------------------------------------------------- echo. goto :if_after_file3_exists :recompress_file4 echo Processing file4 '%file4%.%ext%' in folder '%dir_vid_scr%' echo. ffmpeg -loglevel error -i %file4%.%ext% -c:v libx264 -c:a copy -b:v %bit_rate% -maxrate %bit_rate% -bufsize %bit_rate% %file4%_rcm.%ext% echo Checking video duration for '%file4%.%ext%' echo. for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file4%.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_orig_file4=%%i for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file4%_rcm.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_rcm_file4=%%i echo original file duration: %dur_orig_file4% sec. echo recompressed file duration: %dur_rcm_file4% sec. if %dur_orig_file4% == %dur_rcm_file4% ( echo GREAT. files have same duration. Will remove original video '%file4%.%ext%' del "%file4%.%ext%" echo removed ok. ) echo ---------------------------------------------------------------- echo. goto :if_after_file4_exists :recompress_file5 echo Processing file5 '%file5%.%ext%' in folder '%dir_vid_scr%' echo. ffmpeg -loglevel error -i %file5%.%ext% -c:v libx264 -c:a copy -b:v %bit_rate% -maxrate %bit_rate% -bufsize %bit_rate% %file5%_rcm.%ext% echo Checking video duration for '%file5%.%ext%' echo. for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file5%.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_orig_file5=%%i for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file5%_rcm.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_rcm_file5=%%i echo original file duration: %dur_orig_file5% sec. echo recompressed file duration: %dur_rcm_file5% sec. if %dur_orig_file5% == %dur_rcm_file5% ( echo GREAT. files have same duration. Will remove original video '%file5%.%ext%' del "%file5%.%ext%" echo removed ok. ) echo ---------------------------------------------------------------- echo. goto :if_after_file5_exists и т.д до 40 -------------------------- ----------------------------- ----------------------------- :recompress_file39 echo Processing file39 '%file39%.%ext%' in folder '%dir_vid_scr%' echo. ffmpeg -loglevel error -i %file39%.%ext% -c:v libx264 -c:a copy -b:v %bit_rate% -maxrate %bit_rate% -bufsize %bit_rate% %file39%_rcm.%ext% echo Checking video duration for '%file39%.%ext%' echo. for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file39%.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_orig_file39=%%i for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file39%_rcm.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_rcm_file39=%%i echo original file duration: %dur_orig_file39% sec. echo recompressed file duration: %dur_rcm_file39% sec. if %dur_orig_file39% == %dur_rcm_file39% ( echo GREAT. files have same duration. Will remove original video '%file39%.%ext%' del "%file39%.%ext%" echo removed ok. ) echo ---------------------------------------------------------------- echo. goto :if_after_file39_exists :recompress_file40 echo Processing file40 '%file40%.%ext%' in folder '%dir_vid_scr%' echo. ffmpeg -loglevel error -i %file40%.%ext% -c:v libx264 -c:a copy -b:v %bit_rate% -maxrate %bit_rate% -bufsize %bit_rate% %file40%_rcm.%ext% echo Checking video duration for '%file40%.%ext%' echo. for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file40%.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_orig_file40=%%i for /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %file40%_rcm.%ext% -of default=noprint_wrappers=1:nokey=1"') do set dur_rcm_file40=%%i echo original file duration: %dur_orig_file40% sec. echo recompressed file duration: %dur_rcm_file40% sec. if %dur_orig_file40% == %dur_rcm_file40% ( echo GREAT. files have same duration. Will remove original video '%file40%.%ext%' del "%file40%.%ext%" echo removed ok. ) echo ---------------------------------------------------------------- echo. goto :exit :exit echo PLEASE GOOD BYE! |
|
Отправлено: 15:41, 29-01-2018 |
Ветеран Сообщения: 2728
|
Профиль | Отправить PM | Цитировать Я тупо переписал Ваш код, так как у меня нет Ваших программ, поэтому серьёзно не тестировалось
@Echo Off cls Set "ext=avi" Set "bit_rate=133K" Set "dir_vid_scr=Z:\Users\yura\Downloads\Video" Set /A Nbeg=0 For /F "usebackq delims=:" %%i In (`"FINDSTR /B /L /I /N /C:":FilesSpisok" "%~dpnx0""`) DO Set /A Nbeg=%%i If %Nbeg% EQU 0 Echo !!! No file list found &Pause &Exit /B 240 If Not Exist "%dir_vid_scr%" Echo !!! No folder found "%dir_vid_scr%" &Pause &Exit /B 240 Pushd "%dir_vid_scr%" For /F "usebackq tokens=*" %%i In (`"more +%Nbeg% "%~dpnx0""`) DO ( If /I "%%i"=="GoTo :Eof" GoTo :Cont If Exist "%%i.%ext%" ( Call :Recompress "%%i.%ext%" ) else ( Echo: &Echo !!! File "%dir_vid_scr%\%%i.%ext%" NOT EXISTS! Echo ---------------------------------------------------------------- ) ) :Cont Popd Echo PLEASE GOOD BYE! Pause GoTo :Eof :Recompress Echo: &Echo +++ Processing file %1 in folder "%dir_vid_scr%" ffmpeg -loglevel error -i %1 -c:v libx264 -c:a copy -b:v %bit_rate% -maxrate %bit_rate% -bufsize %bit_rate% "%~n1_rcm%~x1" Echo *** Checking video duration for %1 For /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %1 -of default=noprint_wrappers=1:nokey=1"') Do Set "dur_orig_file=%%i" For /f %%i in ('"ffprobe.exe -v error -show_entries format=duration "%~n1_rcm%~x1" -of default=noprint_wrappers=1:nokey=1"') Do Set "dur_rcm_file=%%i" Echo *** original file duration: %dur_orig_file% sec. Echo *** recompressed file duration: %dur_rcm_file% sec. If "%dur_orig_file%"=="%dur_rcm_file%" ( Echo +++ GREAT. files have same duration. Will remove original video %1 Del %1 &&Echo *** removed ok. ) Echo ---------------------------------------------------------------- GoTo :Eof :FilesSpisok video1 video2 video3 video4 video5 video6 GoTo :Eof Имена video1 ... video40 условные или реальные? |
------- Последний раз редактировалось megaloman, 29-01-2018 в 18:45. Отправлено: 17:37, 29-01-2018 | #2 |
Для отключения данного рекламного блока вам необходимо зарегистрироваться или войти с учетной записью социальной сети. Если же вы забыли свой пароль на форуме, то воспользуйтесь данной ссылкой для восстановления пароля. |
Новый участник Сообщения: 9
|
Профиль | Отправить PM | Цитировать megaloman, ОГРОМНОЕ ВАМ СПАСИБО ЗА ВАШИ ТРУДЫ!!! ПРОСТО ОЧЕНЬ БЛАГОДАРЕН!!! МАЛО КТО В НАШИ ДНИ ПРОСТО ТАК РАДИ ДОБРА И ПОМОЩИ ЧТО-ТО ДЕЛАЕТ!!!! Я БЫ САМ НЕ СМОГ БЫ НАПИСАТЬ ТАКОЙ КОМПАКТНЫЙ КОД КАК У ВАС ВЫШЕЛ!! и тот свой код и так несколько дней сам писал))
Цитата megaloman:
реальные имена файлов могут содержать латиницу(обоих регистров, символы пробела, запятой, нижнего подчеркивания, тире и цифры 0..9). к примеру, реальные имена имеют след. вид Скрытый текст
451P_895K_63403191.avi fk_653_242k_46547292.avi bolshaya-igra-2017.flv voyna-2017.flv вот примерно такие имена.. Цитата megaloman:
Цитата megaloman:
сейчас протестирую ваш код и отпишусь.. но думаю он вполне рабочий!)) |
|||
Отправлено: 00:50, 30-01-2018 | #3 |
Новый участник Сообщения: 9
|
Профиль | Отправить PM | Цитировать Цитата interestingyy:
только можно еще счетчик к слову File добавить вот в этистроки ....... Echo: &Echo +++ Processing file %1 in folder "%dir_vid_scr%" ........... Echo: &Echo !!! File "%dir_vid_scr%\%%i.%ext%" NOT EXISTS! .......... Processing file 1 "file_name.ext" in folder "src_to_folder" Processing file 2 "file_name.ext" in folder "src_to_folder" Processing file 3 "file_name.ext" in folder "src_to_folder" !!! File 1 "src_to_folder\file_name.ext" NOT EXISTS! !!! File 2 "src_to_folder\file_name.ext" NOT EXISTS! !!! File 3 "src_to_folder\file_name.ext" NOT EXISTS! |
|
Отправлено: 07:36, 30-01-2018 | #4 |
Ветеран Сообщения: 2728
|
Профиль | Отправить PM | Цитировать можно еще счетчик
@Echo Off cls Set "ext=avi" Set "bit_rate=133K" Set "dir_vid_scr=Z:\Users\yura\Downloads\Video" Set /A Nbeg=0 For /F "usebackq delims=:" %%i In (`"FINDSTR /B /L /I /N /C:":FilesSpisok" "%~dpnx0""`) DO Set /A Nbeg=%%i If %Nbeg% EQU 0 Echo !!! No file list found &Pause &Exit /B 240 If Not Exist "%dir_vid_scr%" Echo !!! No folder found "%dir_vid_scr%" &Pause &Exit /B 240 Pushd "%dir_vid_scr%" Set /A Count=0 For /F "usebackq tokens=*" %%i In (`"more +%Nbeg% "%~dpnx0""`) DO ( If /I "%%i"=="GoTo :Eof" GoTo :Cont Call :Recompress "%%i.%ext%" ) :Cont Popd Echo PLEASE GOOD BYE! Pause GoTo :Eof :Recompress Set /A Count+=1 Echo: &Echo +++ Processing %Count% file %1 in folder "%dir_vid_scr%" If Not Exist "%dir_vid_scr%\%~1" ( Echo !!! File "%dir_vid_scr%\%~1" NOT EXISTS! Echo ---------------------------------------------------------------- GoTo :Eof ) ffmpeg -loglevel error -i %1 -c:v libx264 -c:a copy -b:v %bit_rate% -maxrate %bit_rate% -bufsize %bit_rate% "%~n1_rcm%~x1" Echo *** Checking video duration for %1 For /f %%i in ('"ffprobe.exe -v error -show_entries format=duration %1 -of default=noprint_wrappers=1:nokey=1"') Do Set "dur_orig_file=%%i" For /f %%i in ('"ffprobe.exe -v error -show_entries format=duration "%~n1_rcm%~x1" -of default=noprint_wrappers=1:nokey=1"') Do Set "dur_rcm_file=%%i" Echo *** original file duration: %dur_orig_file% sec. Echo *** recompressed file duration: %dur_rcm_file1% sec. If "%dur_orig_file%"=="%dur_rcm_file%" ( Echo +++ GREAT. files have same duration. Will remove original video %1 Del %1 &&Echo *** removed ok. ) Echo ---------------------------------------------------------------- GoTo :Eof :FilesSpisok video1 video2 video3 video4 video5 video6 GoTo :Eof |
|
------- Отправлено: 11:40, 30-01-2018 | #5 |
Новый участник Сообщения: 9
|
Профиль | Отправить PM | Цитировать можно было и не писать весь код!) спасибо большое!
|
Отправлено: 11:55, 30-01-2018 | #6 |
Ветеран Сообщения: 2728
|
Профиль | Отправить PM | Цитировать хотелось бы, чтобы автоматически в указанной папке обрабатывались все файлы, имена которых заканчиваются на префикс _ready и имеют расширение, указанное в переменной %ext%
@Echo Off cls Set "ext=avi" Set "bit_rate=133K" Set "dir_vid_scr=Z:\Users\yura\Downloads\Video" Set "Suff=_ready" rem Set "Suff=" If Not Exist "%dir_vid_scr%" Echo !!! No folder found "%dir_vid_scr%" &Pause &Exit /B 240 Set /A Count=0 Pushd "%dir_vid_scr%" For /F "usebackq tokens=*" %%i In (`2^>nul Dir "*%Suff%.%ext%" /B /A:-D`) DO Call :Recompress "%%i" Popd Echo PLEASE GOOD BYE! Pause GoTo :Eof Цитата interestingyy:
|
|
------- Последний раз редактировалось megaloman, 30-01-2018 в 12:32. Отправлено: 12:16, 30-01-2018 | #7 |
Новый участник Сообщения: 9
|
Профиль | Отправить PM | Цитировать megaloman, Ок! понял вас! Спасибо вам огромное за ваши огромные труды! Я бы сам точно не справился!) А вы тут магию сотворили!)
Класс! это мне значительно сократит работу! |
Отправлено: 12:58, 30-01-2018 | #8 |
![]() |
Участник сейчас на форуме |
![]() |
Участник вне форума |
![]() |
Автор темы |
![]() |
Сообщение прикреплено |
| |||||
Название темы | Автор | Информация о форуме | Ответов | Последнее сообщение | |
Разное - Помогите организовать сеть | radiom1x | Сетевые технологии | 6 | 12-09-2011 14:56 | |
CMD/BAT - [решено] Как организовать вызов bat с большим количеством переменных и их обработку? | seriych | Скриптовые языки администрирования Windows | 13 | 27-01-2011 15:48 | |
CMD/BAT - [решено] Как осуществить циклическую обработку параметров %1,%2... в bat-файле | leonaft | Скриптовые языки администрирования Windows | 7 | 14-04-2010 14:03 | |
как просто организовать раздачу файлов с ftp? | illusionmgs | Хочу все знать | 8 | 26-12-2009 11:17 | |
CMD/BAT - [решено] Как исключить обработку одного exe-файла из пакетной обработки нескольких файлов? | Nun-Nun | Скриптовые языки администрирования Windows | 2 | 14-05-2009 12:16 |
|