Solved a simple batch file for copy files and folders

vakili

New member
Local time
12:54 PM
Messages
8
I want to write a batch file that do this for me:

- makes a directory with the "yy.mm.dd.hh.mm" as the directory name,
- copies files and folders from a TEST directory to above destination,
- copies only new (or modified) files from the TEST directory to a separate folder.

Any Idea?
 

My Computer My Computer

At a glance

Windows 7 Ultimate x64
OS
Windows 7 Ultimate x64
To create a directory with the date and time as the name, In a batch file use:

set DirName=%date:~-4,4%.%date:~-7,2%.%date:~0,2%.%time:~0,2%.%time:~3,2%
MD \%DirName%

Then in the same batch file use robocopy to copy files to the new directory

robocopy TEST %DirName% /e

you need to add your own paths and read the robocopy help for the right switches you need.
By default Robocopy copies only files that don't exist in the target directory but because you are creating a new directory every time it will copy every thing in TEST

You could use the /A switch which only copies files with the Archive attribute set.
 
Last edited:

My Computer My Computer

At a glance

Windows 7 Pro 64bit
OS
Windows 7 Pro 64bit
Thanks, It works but a sample output is 4/28.2/.12. 9.31 and it contains special characters.

I found another answer, it works too!

Code:
:: DateTime - Windows NT4 and above
@echo off 
setlocal EnableExtensions
:: Date and time routines by Ritchie Lawrence
:: Windows NT4 and above
:begin
(set today=%date%)
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
  for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
  set %%a=%%d&set %%b=%%e&set %%c=%%f))
(set yy=%yy%&set mm=%mm%&set dd=%dd%)
for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do (
  set hh=%%a&set nn=%%b&set ss=%%c&set cs=%%d)
if 1%hh% LSS 20 set hh=0%hh%
(set hh=%hh%&set nn=%nn%&set ss=%ss%&set tt=%cs%)
if not "%date%"=="%today%" goto :begin

:: The following lines set and create a folder with the timestamp variable
set timestamp=%yy%.%mm%.%dd%.%hh%.%nn%.%ss%
MD %timestamp% 2>nul
 

My Computer My Computer

At a glance

Windows 7 Ultimate x64
OS
Windows 7 Ultimate x64
strange on my system it creates a directory exactly as you asked without special chars.

Glad you found a solution that works for you.
 

My Computer My Computer

At a glance

Windows 7 Pro 64bit
OS
Windows 7 Pro 64bit
Back
Top