我已经设法为一个出版物批量生产全年的条形码。现在需要批处理脚本将文件移动到指定的文件夹。(所以我不必手动完成。也可以节省大量时间并减少错误的可能性)
文件位于名为C:Barcode
的文件夹中文件的结构如下:
一周内每天都有EAN 13条码巫婆结构:977133156901600117 THRU 977133156901605217 52 FILES FOR MON
977133156902300117 THRU 977133156902305217 52 FILES FOR TUE
977133156903000117 THRU 977133156903005217 52 FILES FOR WED
977133156904700117 THRU 977133156904705217 52 FILES FOR THU
385989238246900117 THRU 385989238246900117 52 FILES FOR FRI
977133156906100117 THRU 977133156906105217 52 FILES FOR SAT
977133156907800117 THRU 977133156907805217 52 FILES FOR SUN
脚本应该取这个文件977133156901600117并放入文件夹02_01_MON_01
取文件977133156902300117并将其放入文件夹03_01_TUE_01
...
取文件977133156907805217并将其放入文件夹31_12_SUN-52
解释
9771331569-01-60-01-17 ---左边第一个01告诉这是星期一,第二个01告诉这是一年中的第一周
9771331569-02-30-01-17 --- 02告诉它周二和01告诉这是一年中的第一周
等...
38598923824690-01-17 --- 38598923824690唯一的数字告诉它这周五和01告诉它今年的第一周
...
9771331569-07-80-52-17 --- 07告诉我这是星期天,52告诉它一年中的52周
我希望批处理脚本将这些文件移动到文件夹结构,如下所示: (女巫是由我之前的question)堆叠成员@LotPings提供的
2017/o1_JAN/01_01_SUN_52(2016)
02_01_MON_01
03_01_TUE_01
04_01_WED_01
............
08_01_SUN_01
09_01_MON_02
10_01_TUE_02
............
最后两个diggits代表那一年的一周
即。例如,将文件977133156901600117移动到文件夹02_01_MON_01
(一周中第一天的条形码(MON)和一年中的第一周(01)到文件夹02_01_MON_01
答案 0 :(得分:1)
根据您的要求和例外,此结果应该是您想要的:
C:\TEST\2\2017
├───01_Jan
│ ├───01_01_Sun-52(2016)
│ ├───02_01_Mon-01
│ │ 977133156901600117
│ ├───03_01_Tue-01
│ │ 977133156902300117
│ ├───04_01_Wed-01
│ │ 977133156903000117
│ ├───05_01_Thu-01
│ │ 977133156904700117
│ ├───06_01_Fri-01
│ │ 385989238246900117
│ ├───07_01_Sat-01
│ │ 977133156906100117
│ ├───08_01_Sun-01
│ │ 977133156907800117
│ ├───09_01_Mon-02
│ │ 977133156901600217
│ ├───10_01_Tue-02
│ │ 977133156902300217
│ ├───11_01_Wed-02
│ │ 977133156903000217
│ ├───12_01_Thu-02
│ │ 977133156904700217
│ ├───13_01_Fri-02
│ │ 385989238246900217
│ ├───14_01_Sat-02
│ │ 977133156906100217
│ ├───15_01_Sun-02
│ │ 977133156907800217
│ ├───16_01_Mon-03
│ │ 977133156901600317
...
如果您使用ISO8601日历周,仍然不太舒服 调整Base和Barcode文件夹以适合您的环境。
:: Q:\Test\2017\07\24\SO_45280824.cmd
:: https://stackoverflow.com/questions/45280824/batch-script-to-move-ean-13-barcode-files-to-designated-ymd-folders
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
Set "Base=C:\Test\2"
PushD "C:\Test\2\Barcode"
:: To be more efficient get month/day names array
For %%A in (:01:Jan:Mon: :02:Feb:Tue: :03:Mar:Wed: :04:Apr:Thu:
:05:May:Fri: :06:Jun:Sat: :07:Jul:Sun: :08:Aug::
:09:Sep:: :10:Oct:: :11:Nov:: :12:Dec::
) do for /F "tokens=1-3 delims=:" %%l in ("%%A") do (
set "MonN[%%l]=%%m"
set "DayN[%%l]=%%n"
)
For %%F in (*) Do Call :GetFolder %%F
Pause
PopD
Goto :Eof
:GetFolder
Rem 012345678901234567
Rem 977133156901600117
Rem ISSN d# wk#
Rem publica C yy
Set "File=%~1"
Set "yn=20%File:~16,2%
Set "cw=%File:~14,2%
Set "dw=%File:~10,2%
If "%File:~0,13%" Equ "3859892382469" Set "dw=05"
Call :WeekToDate %yn% %cw% %dw% yy mm dd
Set "Folder=%Base%\%yy%\%mm%_!MonN[%mm%]!\%dd%_%mm%_!DayN[%dw%]!-%cw%"
If %YY% neq %yn% Set "Folder=%Folder%(%yy%)"
IF exist "%Folder%" (
Move %1 "%Folder%" >Nul 2>&1
Echo moved %1 =^> "%Folder%"
) Else (
Echo Check %1 "%Folder%"
Pause
)
Goto :Eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:WeekToDate %yn% %cw% %dw% yy mm dd
::
:: By: Ritchie Lawrence, 2002-10-04. Version 1.0
::
:: Func: Returns a calEndar date from an ISO 8601 Week date.
:: For NT4/2000/XP/2003.
::
:: Args: %1 year to convert, 2 or 4 digits (by val)
:: %2 calEndar week to convert, 2 digits, 01 to 53 (by val)
:: %3 day of week to convert, 1 digit, 1 to 7 (by val)
:: %4 var to receive year, 4 digits (by ref)
:: %5 var to receive month, 2 digits, 01 to 12 (by ref)
:: %6 var to receive day of month, 2 digits, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SetLocal EnableExtensions
Set yn=%1&set cw=%2&set dw=%3
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
Set /a cw=100%cw%%%100,d=3210654
Set /a z=14-1,z/=12,y=yn+4800-z,m=1+12*z-3,Jt=153*m+2
Set /a Jt=Jt/5+1+y*365+y/4-y/100+y/400-32045,wt=Jt%%7
Call set at=%%d:~%wt%,1%%&set /a Jt=at+Jt-3
Set /a Jt=Jt+7*cw+dw-9,a=Jt+32045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
Set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
Set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
Endlocal&set %4=%yy%&set %5=%mm%&set %6=%dd%&Goto :Eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::