a simple batch file for copy files and folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
NabiVakili
Posts: 2
Joined: 26 Apr 2012 02:09

a simple batch file for copy files and folders

#1 Post by NabiVakili » 26 Apr 2012 02:12

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?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: a simple batch file for copy files and folders

#2 Post by foxidrive » 26 Apr 2012 05:18

This will create the folder.

Code: Select all

:: 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

 

NabiVakili
Posts: 2
Joined: 26 Apr 2012 02:09

Re: a simple batch file for copy files and folders

#3 Post by NabiVakili » 27 Apr 2012 22:58

Thank you!
It's amazing.
It help me a lot.

How can I copy only new (or modified) files?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: a simple batch file for copy files and folders

#4 Post by foxidrive » 28 Apr 2012 06:40

Perhaps xcopy with the /m switch - read the help.

xcopy /?

Post Reply