开发者

Create a batch file to rename and move files with user input

I have very limited knowledge of DOS commands (mainly simple move/copy/del/rename commands) and I would like some assistance in creating a batch file that does the following steps:

  1. Prompts the user to enter in a Version Number in an input box.

  2. Validates the user's input to ensure that it is entered as major version, hyphen, minor version (e.g 5-10)

  3. Searches the current folder where the batch file is being run from and renames all PDF's by appending the version number and a hard-coded description to that file.

    开发者_运维知识库For example, an original file of EMDM.pdf, should be renamed as EMDM_5-10_Software Operations Manual.pdf (note the underscore before and after the version number, and spaces in the description text)

  4. Goes to \webserver\downloads and 'MOVES' the PDF file in that location that starts with "EMDM" and ends with "Software Operations Manual.pdf" to \webserver\downloads\supserseded

  5. Once the previous version PDF has been moved (backed up), 'COPY' the newly renamed PDF that exists in the same folder as the bacth file to \webserver\downloads

  6. Once successfully, moved, delete the PDF file that exists in the same folder as the bacth file.

Thank you in advanced.


@echo off
:getversion
REM 1.
set /p VersionNumber=Enter the Version Number: 
REM 2.
for /f "tokens=1-3 delims=-" %%a in ("%VersionNumber%") do set Major=%%a& set Minor=%%b
REM 2.1 Revision of Version Number format
if not "%Major%-%Minor%" == "%VersionNumber%" goto getversion
REM 2.2 Revision of Major and Minor be numbers
set /a NMajor=Major, NMinor=Minor > NUL
if not "%NMajor%" == "%Major%" goto getversion
if not "%NMinor%" == "%Minor%" goto getversion
REM 3.
for %%a in (*.PDF) do ren "%%a" "%%~Na_%VersionNumber%_Software Operations Manual.pdf"
REM 4.
pushd \webserver\downloads
move "EMDM*Software Operations Manual.pdf" supserseded
REM 5.
popd
copy "EMDM*Software Operations Manual.pdf" \webserver\downloads
REM 6.
del "EMDM*Software Operations Manual.pdf"
REM Steps 5 and 6 above is the same as just one MOVE

I modified the revision of the Version Number by an easier method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜