Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: a simple batch file for copy files and folders

26 Apr 2012   #1
vakili

Windows 7 Ultimate x64
 
 
a simple batch file for copy files and folders

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 System SpecsSystem Spec
.
26 Apr 2012   #2
b3achcomber

Windows 7 Pro 64bit
 
 

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.
My System SpecsSystem Spec
28 Apr 2012   #3
vakili

Windows 7 Ultimate x64
 
 

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 System SpecsSystem Spec
.

29 Apr 2012   #4
b3achcomber

Windows 7 Pro 64bit
 
 

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 System SpecsSystem Spec
Reply

 a simple batch file for copy files and folders




Thread Tools




Similar help and support threads
Thread Forum
[Help] Batch File move every 15.000 files to another folders
Hi guys I'm new here, please help I have about 2 million email files that i want to convert into mbox files. but the tool i used only can convert every 15.000 files. so i need a batch file that can move this 2 million files into another folder (15.000 files each folder) and the folder name...
General Discussion
.bat file, batch coding simple variable use
@echo off color C SET IPaddress=0 set /p IPaddress=Please enter the destination Ip Address: color A ping IPaddress pause okay, so i want the IPaddress variable to be used as the ipaddress to be pinged. When i run this, it is ineffective. Can someone teach me as why and how to properly code...
Software
Batch file to copy files from C drive to USB
Hi all, To increase our backup solutions, we have decided to backup our SQL database every hour to a folder within the C drive (we couldn't get it to backup straight to a USB drive). So now we need a way (batch file best solution?) to copy these files to the USB drive, lets say every 1.05hours...
Backup and Restore
search multiple files, copy+paste to new folder (batch file software?)
I am a complete newbie when it comes to batch files and batch file software, so apologies in advance. I've done some research on Google etc but I seem to just be getting more and more confused trying to use various different scripts and programs and reading different info on various websites. ...
General Discussion
Batch file or Exe to copy & rename directory and update files
I require a batch file or free utility that i can redistribute from my web site to other users, (gamers) that will copy the contents of a directory inside their game to a new location and re-name the directory at the same time. Something like this; Copy "Genesis\Vehicles\truck\diesel\4tonbaker"...
General Discussion
Open Multiple Files one click - simple bat/batch file
Hey, I have a simple batch file to load multiple files with one click, but it's not working. When I run it, it simply very quickly pops up the cmd dialog, which quickly disappears, and nothing is loaded. I've tried 'running as administrator' - same problem. File is xxxxx.bat
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 23:13.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App