【发布时间】:2017-06-15 08:51:05
【问题描述】:
这是我在这个网站上的第一篇文章,但由于我已经在 stackoverflow 上找到了很多帮助,所以我现在自己问这个问题。我没有找到这个问题的答案。我的英语不是很好,而且我的问题很复杂,希望你们都能理解我。如果没有,或者有任何问题需要帮助我,请随时提出。
所以我想制作一个通过扩展名移动文件的批处理文件(在我的情况下,它是 .pdf),但不是全部。我知道有这个命令:
move "Y:\Scan\*.pdf" "Y:\Scan\Archive\"
但这会将所有 pdf 文件移动到存档文件夹,我不希望这样。 为了更好地了解我的计划是什么,我想需要一个简短的描述。 想象一下,您有一台家庭服务器,并且您的计算机已连接到它,还有一台打印机和一台扫描仪。我的家庭办公室的文件夹中有许多文档,我希望将它们全部放在我的服务器上。这是通过扫描这些文件夹中的所有纸张来完成的。每次我扫描某些东西时,它都会以 .pdf 格式保存在我本地计算机上的文件夹中,按时间排序,如下所示:2017-06-15-10-30.pdf
我当前的脚本要求用户输入 3 次。一次是村庄名称,一次是街道名称,一次是房屋编号,因为档案文件夹的名称应与其所指的相应房屋相同。所以我的批处理中已经有这 3 个输入,并且整个文件夹名称也保存在一个新变量中。
我的计划是现在询问用户有多少 pdf 对应于最后创建的文件夹,无论用户输入什么,这个数量的文件都将存储在该文件夹中。为了更好地理解这一点,这是我到目前为止所做的(我的批处理代码)。
@echo off
cls
title Archive-Script (by Relentless)
color 0b
:reset
cls
REM This is the village's name
SET ON=""
REM This is the street's name
SET SN=""
REM This is the number of the house
SET HN=""
REM This is a variable to store whether the user wants to reset the variables or not (used later)
SET RESET=""
:start
cls
IF %RESET% == N echo To overwrite the village's name, please enter the name again and hit enter. If you don't want to overwrite the name, just hit enter!
IF NOT %RESET% == N echo Please enter the village's name (confirm by pressing enter):
IF %RESET% == N echo Current name: %ON%
set /p "ON="
echo The village's name was set to %ON%!
echo.
IF %RESET% == N echo To overwrite the street's name, please enter the name again and hit enter. If you don't want to overwrite the name, just hit enter!
IF NOT %RESET% == N echo Please enter the street's name (confirm by pressing enter):
IF %RESET% == N echo Current name: %SN%
set /p "SN="
echo The street's name was set to %SN%!
echo.
IF %RESET% == N echo To overwrite the house's number, please enter the number again and hit enter. If you don't want to overwrite the number, just hit enter!
IF NOT %RESET% == N echo Please enter the house's number (confirm by pressing enter):
IF %RESET% == N echo Current number: %HN%
set /p "HN="
echo The house's number was set to %HN%!
echo.
echo.
echo.
echo.
echo.
SET FOLDERNAME="%ON%, %SN% %HN%"
echo The folder %FOLDERNAME% will now be created!
mkdir ""%FOLDERNAME%""
timeout /t 2 /nobreak
:pdfmove
cls
echo How many pdf-files are corresponding to the latest created folder?
set /p "PDF="
for /l %%x in (1,1,%PDF%) do (
echo %%x
move Y:\Scan\*.pdf Y:\Scan\%FOLDERNAME%\
)
:resetoption
cls
echo %ON%
echo %SN%
echo %HN%
echo.
echo Should the variables be resetted again? (J/N)
set /p "RESET="
IF %RESET% == J goto reset
IF %RESET% == N goto start
如您所见,我已经尝试实现 move 选项,但这将移动所有 pdf 文件,而不是每个 for 循环一个。任何人都可以帮助我吗?我想代码很容易理解。
Greetz 无情
【问题讨论】:
标签: batch-file command move