使用bat文件夹创建 [英] Creating folder using bat file

查看:168
本文介绍了使用bat文件夹创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写使用当前的日期和时间,文件夹名这将创建一个新的文件夹中的bat文件。
我想出了以下内容:

I need to write a bat file which creates a new folder using current date and time for folder name. I came up with the following:

for /f "tokens=1-3 delims=:," %%i in ("%TIME%") do md %DATE%-%%i.%%j.%%k

这是否code有什么破绽?是否有更简单/更自然的方式做到这一点?

Does this code has any flaws? Is there an easier / more natural way to do it?

推荐答案

您可以使用一个子和内置%DATE%和%TIME%变量来做到这一点:

You can use a substring and the built-in %DATE% and %TIME% variables to do this:

@echo OFF

:: Use date /t and time /t from the command line to get the format of your date and
:: time; change the substring below as needed.

:: This will create a timestamp like yyyy-mm-dd-hh-mm-ss.
set TIMESTAMP=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%-%TIME:~0,2%-%TIME:~3,2%-%TIME:~6,2%

@echo TIMESTAMP=%TIMESTAMP%

:: Create a new directory
md "%1\%TIMESTAMP%"

这篇关于使用bat文件夹创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆