4

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.

jardane
  • 461
  • 4
  • 11
  • 21

6 Answers6

4

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!

Jony Adamit
  • 2,818
  • 31
  • 40
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.

Erik Eidt
  • 18,115
  • 1
  • 24
  • 47
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
TDG
  • 5,460
  • 2
  • 28
  • 49
mangyan
  • 26
  • 3
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
Mofi
  • 42,677
  • 15
  • 72
  • 128
Anna Malai
  • 11
  • 1
0

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

zx485
  • 26,827
  • 28
  • 51
  • 55
0

Just rename the folder with Erik's suggestion:

move FolderName FolderName_%date:~7,2%%date:~4,2%%date:~12,4%
hoggar
  • 3,483
  • 5
  • 26
  • 34