简体   繁体   English

创建批处理文件以使用用户输入重命名和移动文件

[英]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: 我对DOS命令的知识非常有限(主要是简单的移动/复制/删除/重命名命令),我想在创建批处理文件时做一些帮助,它执行以下步骤:

  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 (eg 5-10) 验证用户的输入以确保将其输入为主要版本,连字符,次要版本(例如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. 搜索运行批处理文件的当前文件夹,并通过将版本号和硬编码描述附加到该文件来重命名所有PDF。

    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) 例如,EMDM.pdf的原始文件应重命名为EMDM_5-10_Software Operations Manual.pdf(注意版本号前后的下划线和说明文本中的空格)

  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 转到\\ webserver \\ downloads并'移动'以“EMDM”开头并以“Software Operations Manual.pdf”结尾的位置的PDF文件到\\ 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 移动(备份)以前版本的PDF后,'复制'与bacth文件位于同一文件夹中的新重命名的PDF到\\ webserver \\ downloads

  6. Once successfully, moved, delete the PDF file that exists in the same folder as the bacth file. 成功移动后,删除与bacth文件位于同一文件夹中的PDF文件。

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. 我通过一种更简单的方法修改了版本号的修订版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM