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 fol
@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
This will show you how to set the date in variables.
The rest is just using copy/xcopy to that folder :)
Tell me if you need more elaboration on how to do it.
Cheers!
[EDIT]: Here is the complete solution:
Create a file using notepad -> save as "something.bat" OR using CMD -> copy con something.bat (and once you're done press Ctrl-Z) And paste the following code:
@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
Hope this helps!
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
Just rename the folder with Erik's suggestion:
move FolderName FolderName_%date:~7,2%%date:~4,2%%date:~12,4%
set TODAY=%date:~10,4%%date:~7,2%%date:~4,2%
is an alternative way to get the date part into a shell variable
from: http://stevesgeekspeak.com/2010/01/howto-get-variable-substrings-in-batcmd-scripts/
Jony ... FTW, of course, for having the whole answer.
Was having trouble with this one myself, but directions without further ado:
Put your source folder here after the .bat
file:
yourscript.bat c:\users\myname\Desktop\sourcefolder
Hope that helps someone else, took me a few seconds :D