1 (изменено: alexii, 2013-02-18 10:32:06)

Тема: CMD/BAT: Запись в файл имени файла по маске

Здравствуйте. Нужен батник, который будет записывать в файл version версию файла, который называется blablabla-1.2.3.blablabla.dat
то есть в version должен быть только кусок 1.2.3 -все цифры, не теряя точки. Привязываться к порядковому номеру цифр нельзя.

Сам скрипт пишется для обновления firefox на сервере компании с большим количеством терминальных пользователей.

@Echo Off
md %CD%\pub\
xcopy "update*" ^
"%USERPROFILE%\AppData\Local\Mozilla\Firefox\Mozilla Firefox\updates\0\" /Y
cd pub\
del *.* /q
"C:\Program Files\GnuWin32\bin\wget" -nH ftp://anonymous:anonymous@ftp.mozilla.org^
/pub/mozilla.org/firefox/releases/latest/update/win32/ru/*complete.mar
ren *.complete.mar* update.mar
xcopy "update.mar" ^
"%USERPROFILE%\AppData\Local\Mozilla\Firefox\Mozilla Firefox\updates\0\" /Y
cd ..
@Echo off
taskkill /F /IM firefox.exe
start /d"C:\Program Files (x86)\Mozilla Firefox" firefox.exe
rd pub /q /s

2

Re: CMD/BAT: Запись в файл имени файла по маске

Поясните подробнее. На реальных примерах. Что известно об имени файла и его местоположении?

3 (изменено: alfatedg, 2013-02-18 10:04:29)

Re: CMD/BAT: Запись в файл имени файла по маске

файл лежит по адресу ftp://anonymous:anonymous@ftp.mozilla.org^
/pub/mozilla.org/firefox/releases/latest/update/win32/ru/*complete.mar
содержит полное обновление для firefox. Для успешного обновления надо эту версию писать в файл version
причем, есть предположение, что они-разрабы лисы, могут применить в версии и буквы

4

Re: CMD/BAT: Запись в файл имени файла по маске

А я сказал, префиксу (CMD/BAT: ) — быть!

Используйте разбор:

@echo off
setlocal enableextensions enabledelayedexpansion

for /f "usebackq delims=" %%i in (`dir /b "firefox-*.*.*.complete.mar"`) do (
    set sName=%%~ni
    set sVersion=!sName:firefox-=!
    >"version" echo !sVersion:.complete=!
)

endlocal
exit /b 0

5

Re: CMD/BAT: Запись в файл имени файла по маске

Огромное спасибо, alexii. Это было то, что нужно!
конечный вариант выглядит так

@Echo Off
setlocal enableextensions enabledelayedexpansion
xcopy "update*" ^
"%USERPROFILE%\AppData\Local\Mozilla\Firefox\Mozilla Firefox\updates\0\" /Y
md %CD%\pub\
cd pub\
del *.* /q
"C:\Program Files\GnuWin32\bin\wget" -nH ftp://anonymous:anonymous@ftp.mozilla.org^
/pub/mozilla.org/firefox/releases/latest/update/win32/ru/*complete.mar
for /f "usebackq delims=" %%i in (`dir /b "firefox-*.*.*.complete.mar"`) do (
    set sName=%%~ni
    set sVersion=!sName:firefox-=!
    >"update.version" echo !sVersion:.complete=!
)
ren *.complete.mar* update.mar
xcopy "update.mar" ^
"%USERPROFILE%\AppData\Local\Mozilla\Firefox\Mozilla Firefox\updates\0\" /Y
xcopy "update.version" ^
"%USERPROFILE%\AppData\Local\Mozilla\Firefox\Mozilla Firefox\updates\0\" /Y
cd ..
taskkill /F /IM firefox.exe
start /d"C:\Program Files (x86)\Mozilla Firefox" firefox.exe
rd pub /q /s

6 (изменено: UNDYING, 2013-02-18 16:13:42)

Re: CMD/BAT: Запись в файл имени файла по маске

alfatedg пишет:

Для успешного обновления надо эту версию писать в файл version

А где он должен находиться? И каков формат?
Судя по докам - там xml в utf-8, и как в него вы батником писать будете? Может проще по инструкции, благо там уже всё написано.


@echo off
set wdir=%cd%
copy /y %Programfiles%\"Mozilla Firefox"\updater.* ./
wget bla-bla-bla ...
cd /d %Programfiles%\"Mozilla Firefox"
taskkill /F /IM firefox.exe
start /w %wdir%\updater.exe %wdir% %cd%
(type %wdir%\update.status | find /i "succeeded" 2>&1 >nul) || (
         echo update aborted
         exit /b 1)
type %wdir%\update.log > uninstall\uninstall.update
start /w uninstall\helper.exe /PostUpdate
rd /s/q %wdir%
exit /b 0

7 (изменено: alfatedg, 2013-02-18 13:47:42)

Re: CMD/BAT: Запись в файл имени файла по маске

UNDYING, собственно, батник и использует эту инструкцию. файлы обновления должны лежать в корне с батником. Обновление же происходит при запуске firefox на последнем этапе

update.version у меня находится в папке pub\ а потом копируется в %USERPROFILE%\AppData\Local\Mozilla\Firefox\Mozilla Firefox\updates\0\

Скрипт писал для выволнения на сервере ночью. Запустил и забыл

8

Re: CMD/BAT: Запись в файл имени файла по маске

alfatedg пишет:

UNDYING, собственно, батник и использует эту инструкцию. файлы обновления должны лежать в корне с батником. Обновление же происходит при запуске firefox на последнем этапе

А зачем тогда:

xcopy "update.mar" ^
"%USERPROFILE%\AppData\Local\Mozilla\Firefox\Mozilla Firefox\updates\0\" /Y
xcopy "update.version" ^
"%USERPROFILE%\AppData\Local\Mozilla\Firefox\Mozilla Firefox\updates\0\" /Y

?

9 (изменено: alfatedg, 2013-02-18 13:54:13)

Re: CMD/BAT: Запись в файл имени файла по маске

update.mar берется с ftp. это и есть обновление. в update.version пишется версия из имени файла. Другое дело, что эту команду можно было написать одной строчкой, но мне так проще

10

Re: CMD/BAT: Запись в файл имени файла по маске

и использует эту инструкцию

Инструкция:

Steps for Windows

    Create a directory outside of the application's installation directory to be updated (e.g. C:\app-update\). This directory will be referred to as the outside directory throughout the instructions below so please make a note of its location. Grant the user account you are using Full Control permissions on this directory if it doesn't have these permission already.
    Copy updater.exe from the application's installation directory that is to be upgraded into the outside directory. If you would like to display the updater user interface while it is applying the update also copy the updater.ini into the outside directory.
    Download the appropriate .mar file and put it into the outside directory you created (see Where to get a mar file).
    Rename the mar file you downloaded to update.mar.
    Open a command prompt by running cmd.exe. On Windows Vista or greater you may need to launch cmd.exe with "Run as administrator" (available in the context menu when right clicking cmd.exe).
    Change the working directory to the application's installation directory by using the cd command (e.g. for Firefox cd "C:\Program Files\Mozilla Firefox"). Important: running the update from within another directory will fail to update the existing installation properly with Firefox 3.6.x and below, SeaMonkey 2.0.x and below, and Thunderbird 3.1.x and below.
    Close all instances of the application that are running on the system including those being used by other users before going any further. Important: not doing so will cause the update to fail.
    For Firefox 4.0.x and above, SeaMonkey 2.1.x and above, or Thunderbird 5.0.x and above run the following from the command prompt

    <path to outside directory>\updater.exe <path to outside directory> <path to installation directory>


    For Firefox 3.5.x and 3.6.x, SeaMonkey 2.0.x, or Thunderbird 3.0.x and 3.1.x run the following from the command prompt

    <path to outside directory>\updater.exe <path to outside directory>\


    For Firefox 3.0.x or Thunderbird 2.0.x run the following from the command prompt

    <path to outside directory>\updater.exe <path to outside directory>\ 0

    Note: The "0" parameter passed on the command line specifies the PID of a process to wait on before applying the update. When applying updates manually this should be 0 to disable the wait step.
    After the update has completed a file named update.status will be created in the outside directory. Open the update.status status file in an editor (e.g. notepad.exe). If the update is successful then the file will contain the text "succeeded". If it does not contain the text "succeeded", then the update.log file may be consulted to diagnose at what step the update failed. A failed update should leave the original application's installation intact. DO NOT continue to the next section unless the update succeeded.
    Copy the update.log to the uninstall directory inside of the application's installation directory.
    Rename it to uninstall.update.
    Run the following from the command prompt

    <path to installation directory>\uninstall\helper.exe /PostUpdate

11

Re: CMD/BAT: Запись в файл имени файла по маске

http://byffox.sourceforge.net/forum/top … mp;topic=6 инструкция на русском

12

Re: CMD/BAT: Запись в файл имени файла по маске

http://byffox.sourceforge.net/forum/top … mp;topic=6 инструкция на русском

.\firefox-update\updater.exe .\firefox-update 0

Устарела

For Firefox 4.0.x and above, SeaMonkey 2.1.x and above, or Thunderbird 5.0.x and above run the following from the command prompt

    <path to outside directory>\updater.exe <path to outside directory> <path to installation directory>

И как бы инструкция с неясного форума и Wiki Mozilla - разные вещи.
Хотя как подсказывает опыт vlc... официальный источник тоже непанацея.