I need to make a batch file that will make a folder with today's date in month day year format (example 080112). Then once it's created i need to move files from a set folder in to the folder it just created. To be honest i don't know how to make a batch file.
问问题
20390 次
6 回答
4
其余的只是使用 copy/xcopy 到该文件夹:)
告诉我您是否需要详细说明如何操作。
干杯!
[编辑]:这是完整的解决方案:
使用记事本创建文件 -> 另存为“something.bat”或使用 CMD -> 复制 con something.bat(完成后按 Ctrl-Z)并粘贴以下代码:
@echo off
IF "%1"=="" GOTO MissingArgument
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set TODAY=%month%%day%%year%
md %TODAY%
MOVE %1\*.* %TODAY%
GOTO end
:MissingArgument
echo Incorrect Syntax: Source Folder Name Required!
:end
希望这可以帮助!
于 2012-08-01T14:44:22.497 回答
4
set TODAY=%date:~10,4%%date:~7,2%%date:~4,2%
是将日期部分放入 shell 变量的另一种方法
来自:http ://stevesgeekspeak.com/2010/01/howto-get-variable-substrings-in-batcmd-scripts/
Jony ... FTW,当然,因为有完整的答案。
于 2012-08-01T23:18:46.587 回答
1
FOR /f "tokens=2-4 delims=/ " %%i in ('DATE/T') do SET today_fname=%%i%%j%%k
cd c:\myfolder\%today_fname%
REM This creates a folder named 05242016 in c:\myfolder
于 2016-05-24T10:05:05.637 回答
1
@echo on
:: 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 e:\example\"%1\%TIMESTAMP%"
xcopy /y c:\windows E:\windows\%TIMESTAMP% /e
@echo on
于 2016-09-08T12:36:23.783 回答
0
我自己遇到了这个问题,但不用多说,将您的源文件夹放在文件后面.bat
:
yourscript.bat c:\users\myname\Desktop\sourcefolder
希望对其他人有所帮助,花了我几秒钟的时间:D
于 2013-05-10T15:16:33.240 回答
0
Just rename the folder with Erik's suggestion:
move FolderName FolderName_%date:~7,2%%date:~4,2%%date:~12,4%
于 2016-03-27T00:59:46.960 回答