毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> net技术 >> 正文

bat批处理保留当前年月的文件夹其它的删除

更新时间:2013-7-25:  来源:毕业论文

bat批处理保留当前年月的文件夹其它的删除

E盘中text文件夹下有许多文件夹,都是以年和月命名的,实现保留当前年月的文件夹,其他的全部删掉。   这个怎么实现呢

for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (
set Day=%%k
set Month=%%j
set Year=%%l
set DATE=%%k/%%j/%%l)
I am try to get the date into the above variables in a batch script, but currently the date comes out as

2011/04/
Any suggestions on how to fix this?
You don't get what you expected because %DATE% returns the current date using the windows settings for the "short date format". This setting is fully (endlessly) customizable.

One user may configure its system to show the short date as Fri040811; while another user (even in the same system) may choose 08/04/2011. It's a complete nightmare for a BAT programmer.

One possible solution is to use WMIC, instead. WMIC is the WMI command line interface to WMI. WMI Windows Management Instrumentation is the http-://en.wikipedia.-org/wiki/Windows_Management_Instrumentation

WMIC Path Win32_LocalTime Get Day,Hour,Minute,Month,Second,Year /Format:table
returns the date in a convenient way to directly parse it with a FOR.

Completing the parse and putting the pieces together

 FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO (
    SET /A TODAY=%%F*10000+%%D*100+%%A
 )

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。