查看: 2647|回复: 6
收起左侧

[求助] 批处理建立一个以当前年份、周别、星期为名的文件夹

[复制链接]
xp163
发表于 2014-4-13 19:23:34 | 显示全部楼层 |阅读模式
脚本完成的任务:

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 "拷备完成" ,, "友情提示"
阡语陌路
发表于 2014-5-3 09:18:16 | 显示全部楼层
试了一下,还不错,感谢分享!
ywjco
发表于 2014-5-6 22:08:38 | 显示全部楼层
则自动根据当前日期建立文件夹名称为:2011_33_MON


中文的系统,支持用中文的目录,直接改两句代码就行。如下

'建立一个以当前年份、周别、星期为名的文件夹.VBS


Dim NowYear, NowWeek, NowWeekDay, Arr, FolderName, FSO, Path
Arr = split("星期日,星期一,星期二,星期三,星期四,星期五,星期六", ",")
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 "拷备完成" ,, "友情提示"
早春新柳
发表于 2014-5-9 16:11:32 | 显示全部楼层
这个不错
a82687932
发表于 2014-5-11 17:40:08 | 显示全部楼层
有点意思
\\Kaizen\
发表于 2014-5-16 20:54:07 | 显示全部楼层
vba也可以
power2013
发表于 2014-5-27 18:38:33 | 显示全部楼层
谢谢 挺好用的
您需要登录后才可以回帖 登录 | 快速注册

本版积分规则

手机版|杀毒软件|软件论坛| 卡饭论坛

Copyright © KaFan  KaFan.cn All Rights Reserved.

Powered by Discuz! X3.4( 沪ICP备2020031077号-2 ) GMT+8, 2024-11-25 12:38 , Processed in 0.126952 second(s), 16 queries .

卡饭网所发布的一切软件、样本、工具、文章等仅限用于学习和研究,不得将上述内容用于商业或者其他非法用途,否则产生的一切后果自负,本站信息来自网络,版权争议问题与本站无关,您必须在下载后的24小时之内从您的电脑中彻底删除上述信息,如有问题请通过邮件与我们联系。

快速回复 客服 返回顶部 返回列表