0

我想使用批处理重命名一些文件。
我需要它看起来像DD.MM.YY - # week randomname
所以让我们说2.7.2013-27.week abcdefg.xls

到目前为止,我正在使用

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do (
  rename "C:\TEST\123.xlsx" %%e%%f%%g.xlsx
)

它提出DD.MM.YYYY并且非常适合第一部分。
剩下的可以帮忙吗?

4

3 回答 3

3
@echo off
for /F "tokens=1-5 delims=/" %%d in ("%date%") do (
   set ddmmyy=%%e.%%f.%%g
   set /A dd=1%%e-100, mm=1%%f-100, yy=%%g, yyM1=yy-1
)
rem Get Julian Day Number of today's date
if %mm% lss 3 set /A mm+=12, yy-=1
set /A a=yy/100, b=a/4, c=2-a+b, e=36525*(yy+4716)/100, f=306*(mm+1)/10, jdn=c+dd+e+f-1524
rem Subtract Julian Day Number of January/1st (get number of days in year)
set /A a=yyM1/100, b=a/4, c=2-a+b, e=36525*(yyM1+4716)/100, f=306*14/10, days=jdn-(c+1+e+f-1524)+1
rem Get number of week
set /A week=(days+3)/7+1
ECHO rename "C:\TEST\123.xlsx" "%ddmmyy% - %week%.week !random!!random!.xlsx"

参考:http: //quasar.as.utexas.edu/BillInfo/JulianDatesG.html

于 2013-07-03T19:59:19.037 回答
2

的 Windows 代码:

awk "BEGIN {print strftime(\"%U\",mktime(\"YYYY MM DD hh mm ss\"))}"

例子:

>for /f %i in ('awk "BEGIN {print strftime(\"%U\",mktime(\"2013 07 03 12 00 00\"))}"') do @echo %i
26
于 2013-07-03T12:20:49.993 回答
1

这会给你日期,一年中的一周,你可以使用!随机!随机!延迟扩展为您提供随机文件名。

这是一个示例脚本 - 如果这对您很重要,那么年月日会在文件夹中正确排序。

@echo off
call datetime.bat /quiet
setlocal enabledelayedexpansion
for %%a in (*.xlsx) do (
  rename "%%a" "%year%.%month%.%day% - %woy%.week !random!!random!%%~xa"
)

这是 datetime.bat

  :: date time using WSH/VBS
  :: datetime.bat V4.2
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ::
  :: This uses Windows Scripting Host to set variables to
  :: the current date/time/day/day_number/week_of_year etc
  :: for Win9x/ME/NT/W2K/XP/Vista/Win7/Win8 etc
  :: Thanks go to Todd Vargo for his scripting
  ::
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  @echo off
  set TmpFile="%temp%.\tmp.vbs"
  echo> %TmpFile% n=Now
  echo>>%TmpFile% With WScript
  echo>>%TmpFile% .Echo "set m1="   + monthname(month(n), true)
  echo>>%TmpFile% .Echo "set m2="   + monthname(month(n), false)
  echo>>%TmpFile% .Echo "set woy="  + CStr(datepart("ww", n))
  echo>>%TmpFile% .Echo "set year=" + CStr(Year(n))
  echo>>%TmpFile% .Echo "set yr="   + Right(Year(n),2)
  echo>>%TmpFile% .Echo "set month="+ Right(100+Month(n),2)
  echo>>%TmpFile% .Echo "set day="  + Right(100+Day(n),2)
  echo>>%TmpFile% .Echo "set hour=" + Right(100+Hour(n),2)
  echo>>%TmpFile% .Echo "set min="  + Right(100+Minute(n),2)
  echo>>%TmpFile% .Echo "set sec="  + Right(100+Second(n),2)
  echo>>%TmpFile% .Echo "set dow="  + WeekDayName(Weekday(n),1)
  echo>>%TmpFile% .Echo "set dow2=" + WeekDayName(Weekday(n))
  echo>>%TmpFile% .Echo "set iso="  + CStr(1 + Int(n-2) mod 7)
  echo>>%TmpFile% .Echo "set iso2=" + CStr(Weekday(n,2))
  echo>>%TmpFile% End With
  cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
  call "%temp%.\tmp.bat"
  del  "%temp%.\tmp.bat"
  del  %TmpFile%
  set TmpFile=
  set stamp=%year%-%month%-%day%.%hour%_%min%_%sec%

  if not "%~1"=="" goto :EOF

  echo The year  is "%year%" or "%yr%"
  echo The month is "%month%" "%m1%" "%m2%"
  echo The day   is "%day%" "%dow%" "%dow2%"
  echo.
  echo ISO8601 Day-Of-Week number is "%iso%" and week of year is: "%woy%"

  echo.
  echo The time in hh:mm:ss is "%hour%:%min%:%sec%"
  echo The hour   is "%hour%"
  echo The minute is "%min%"
  echo The second is "%sec%"
  echo.

  echo The date and time stamp is "%stamp%"
  echo.
  echo date A yyyymmdd "%year%%month%%day%"
  echo date B mmddyyyy "%month%%day%%year%"
  echo date C ddmmyyyy "%day%%month%%year%"
  echo date D yymmdd   "%yr%%month%%day%"
  echo date E mmddyy   "%month%%day%%yr%"
  echo date F ddmmyy   "%day%%month%%yr%"
  pause
  :: datetime.bat
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
于 2013-07-03T13:44:18.453 回答