脚本完成的任务:
1.自动建立一个以当前年份、周别、星期为名的文件夹,如今天是2011年第33周星期一,则自动根据当前日期建立文件夹名称为:2011_33_MON
2.将特定文件拷入此文件夹,比如*.csv. 如何引用该段代码。
批处理处理方式:
@echo off&set/a Y=%date:~0,4%,M=1%date:~5,2%%%-101,D=1%date:~8,2%%%100
for /l %%a in (1,1,%M%) do set/a "D+=30+(%%a-%%a/8)%%2+!(%%a-2)*(!(Y%%4)&!(!(Y%%100))|!(Y%%400)-2)"
set/a T=(Y-1)*365+Y/4-Y/100+Y/400+1,D+=T-1,M=D/7-T/7+1,"K=!(D%%7)*7+D%%7"
for /f "tokens=%K%" %%a in ("Mon Tue Wed Thu Fri Sat Sun") do set K=%Y%_%M%_%%a
md "%K%\" 2>nul
copy "c:\*.csv" "%K%\"
VBS处理方式:
Dim NowYear, NowWeek, NowWeekDay, Arr, FolderName, FSO, Path
Arr = split("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", ",")
NowYear = Year(Now())
NowWeek = DateDiff("ww", NowYear & "-1-1", Now())
NowWeekDay = Arr(Weekday(Now()))
FolderName = NowYear & "_" & NowWeek & "_" & NowWeekDay
Set FSO = CreateObject("Scripting.FileSystemObject")
Path = CreateObject("Wscript.Shell").CurrentDirectory & "\"'如不是当前目录请自行修改为绝对或相对路径
FSO.CreateFolder FolderName
For Each file In FSO.GetFolder(Path).Files
If LCase(FSO.GetExtensionName(file)) = "csv" Then FSO.CopyFile file, FolderName & "\"
Next
Set FSO = Nothing
MsgBox "拷备完成" ,, "友情提示"
|