所以,我在这里要做的是:
这是我现在所拥有的:
ECHO OFF
COLOR 9E
CLS
:MENU
ECHO(
ECHO( ...............................................
ECHO( Choose month of the year.
ECHO( ...............................................
ECHO(
ECHO 1 - January
ECHO 2 - February
ECHO 3 - March
Echo 4 - April
Echo 5 - May
Echo 6 - June
Echo 7 - July
Echo 8 - August
Echo 9 - September
Echo 10 - October
Echo 11 - November
Echo 12 - December
ECHO 13 - EXIT
ECHO(
SET /P M= Type prefered month, then press ENTER:
IF %M%==1 GOTO JANUARY
IF %M%==2 GOTO FEBRUARY
IF %M%==3 GOTO MARCH
IF %M%==4 GOTO APRIL
IF %M%==5 GOTO MAY
IF %M%==6 GOTO JUNE
IF %M%==7 GOTO JULY
IF %M%==8 GOTO AUGUST
IF %M%==9 GOTO SEPTEMBER
IF %M%==10 GOTO OCTOBER
IF %M%==11 GOTO NOVEMBER
IF %M%==12 GOTO DECEMBER
IF %M%==13 GOTO EOF
:January
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
:February
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
:MARCH
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
:APRIL
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
:MAY
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
:JUNE
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
:JULY
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
:AUGUST
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
:SEPTEMBER
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
:OCTOBER
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
:NOVEMBER
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
:DECEMBER
cd C:\Users\PC\Desktop\Folder
[I am stuck here]
cls
GOTO MENU
我的问题是,我所在的公司,不使用未经许可的软件。为了节省一些钱,他们在工作计算机上安装了7zip。
所以,我的问题是:
如何将在[Month]中创建的 ALL .file类型文件添加到7zip存档,将其命名为[MM_YYYY],并将其移动到另一个文件夹。
如何创建名为[MM_YYYY]的备份文件夹,并只放置那些与所选月份对应的.file类型文件。
答案 0 :(得分:1)
这个脚本适合我的任务。将dir
值更改为您的真实文件夹路径。将此脚本保存到其他文件夹中的 test.bat ,然后从打开的Cmd提示符运行。该脚本假定日期格式为[DD:MM:YYYY]
。要将其与格式[MM:DD:YYYY]
一起使用,请在所有!cmon:~0,2!
出现时将0替换为3。如果有任何错误,请告诉我:
@echo off
setlocal enabledelayedexpansion
set "mes1=Enter the month letter"
set dir=%userprofile%\Desktop\Folder
COLOR 9E
CLS
:MENU
ECHO(
ECHO( ...............................................
ECHO( Choose month of the year.
ECHO( ...............................................
ECHO(
ECHO J - January
ECHO F - February
ECHO M - March
Echo P - April
Echo Y - May
Echo N - June
Echo L - July
Echo U - August
Echo S - September
Echo O - October
Echo V - November
Echo D - December
ECHO X - EXIT
ECHO(
choice /c JFMPYNLUSOVDX /n /m "%mes1%: > " /t 10 /d X
IF %errorlevel% equ 13 (GOTO :end
) else if %errorlevel% LEQ 9 (set i=0%errorlevel%) else (set "i=%errorlevel%")
pushd "%dir%"
for /f "tokens=1,5" %%G in ('dir /o:d /a:-d "%dir%"') do (set cmon=%%G
if "!cmon:~2,1!"=="/" if "!cmon:~0,2!"=="!i!" (set cdir=!cmon:~0,2!-!cmon:~6,4!
(if not exist "!cdir!" md "!cdir!") & copy "%%H" !cdir! >nul))
pushd "!cdir!" & "c:\Program Files\7-Zip\7z.exe" a !cdir!.zip >nul & popd
:end
echo/ & echo All tasks completed
timeout 5 >nul
exit /b
要更好地了解脚本的工作原理,请参阅Extracting Substrings。