Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make batch file that creates a folder with today's date then moves files from a folder in to that newly created folder

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.

like image 978
jardane Avatar asked Dec 27 '22 20:12

jardane


2 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!

like image 139
Jony Adamit Avatar answered Dec 29 '22 10:12

Jony Adamit


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.

like image 33
Erik Eidt Avatar answered Dec 29 '22 10:12

Erik Eidt