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.
6 Answers
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!
- 2,818
- 31
- 40
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.
- 18,115
- 1
- 24
- 47
@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
- 42,677
- 15
- 72
- 128
- 11
- 1
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
- 26,827
- 28
- 51
- 55
- 5
- 2
-
Might be better served as comment on the other solution. – Colin DeClue May 10 '13 at 15:39
Just rename the folder with Erik's suggestion:
move FolderName FolderName_%date:~7,2%%date:~4,2%%date:~12,4%
- 3,483
- 5
- 26
- 34