Make a batch file that creates a folder with today's date, then moves the files from the folder to this newly created folder

I need to make a batch file that will make a folder with today's date in the format of the month in the format of the month (example 080112). Then after creating it, I need to move the files from the installed folder to the folder that she just created. Honestly, I do not know how to make a batch file.

+4
source share
6 answers
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 
+1
source

This will show you how to set the date in variables.

The rest just uses copy / xcopy for this folder :)

Tell me if you need to work out more how to do it.

Hooray!

[EDIT]: Here is the complete solution:

Create a file using notepad -> save as "something.bat" OR using CMD -> copy con something.bat (and as soon as 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!

+4
source
 set TODAY=%date:~10,4%%date:~7,2%%date:~4,2% 

is an alternative way to get part of a date into a shell variable

from: http://stevesgeekspeak.com/2010/01/howto-get-variable-substrings-in-batcmd-scripts/

Jony ... FTW, of course, for the whole answer.

+4
source

@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 / yc: \ windows E: \ windows \% TIMESTAMP% / e

@echo on

+1
source

I had problems with this, but directions without further ado: Put the source folder here after the .bat file:

 yourscript.bat c:\users\myname\Desktop\sourcefolder 

Hope someone helped, took me for a few seconds: D

0
source

Just rename Eric's suggestion folder:

 move FolderName FolderName_%date:~7,2%%date:~4,2%%date:~12,4% 
0
source

All Articles