All About Circuits Forum  

Go Back   All About Circuits Forum > Software, Microcomputing, and Communications Forums > Programmer's Corner

Programmer's Corner Discussion forum for all aspects of programming and software engineering. Any software programming language welcome: C, C++, C#, Fortran, Java, Matlab, etc.

Reply   Post New Thread
 
Thread Tools Display Modes
  #1  
Old 10-17-2009, 04:38 PM
Anthony Quah's Avatar
Anthony Quah Anthony Quah is offline
Member
 
Join Date: Dec 2007
Posts: 77
Default MS DOS command ...

hi guy,

I am working on some dos command to get some folder copy to other location at specific time on daily basic...

My DOS source code
start at 21:44 /every:M,T,W,Th,F cmd /c xcopy C:\123 C:\DeakinU /E


My problem:
I need to get it copy over to new location in a new files name without overwrite the current folder. If tuesday it copy at 21:44, then it will create new folden without overwrite the monday exist folder. How can I do that? If batch files can be use can i get some example for further trial out ?


I thank in advance for any help given...
Reply With Quote
  #2  
Old 10-17-2009, 05:21 PM
jpanhalt jpanhalt is offline
E-book Developer
 
Join Date: Jan 2008
Location: Ohio, USA(GMT-5)
Posts: 1,920
Default

Can you just capture the date and copy to a file of the same name? Use yymmdd format.

John
Reply With Quote
  #3  
Old 10-17-2009, 06:07 PM
SgtWookie's Avatar
SgtWookie SgtWookie is online now
Senior Member
 
Join Date: Jul 2007
Location: Orlando, FL USA
Posts: 8,375
Default

How many versions do you want to keep?
Reply With Quote
  #4  
Old 10-17-2009, 06:11 PM
Anthony Quah's Avatar
Anthony Quah Anthony Quah is offline
Member
 
Join Date: Dec 2007
Posts: 77
Default

jp,
if i put ddmmyy would me I have to set the date ...rather than let it copy by itself .. you see my DOS already set copy at specific time daily ..my problem is i dont want it to overwrite the previous folder..

SgtWookie,
I just need it to have 3 version of folder without overwrite each other..
Reply With Quote
  #5  
Old 10-17-2009, 06:49 PM
SgtWookie's Avatar
SgtWookie SgtWookie is online now
Senior Member
 
Join Date: Jul 2007
Location: Orlando, FL USA
Posts: 8,375
Default

Well, this is overkill ... 10 versions. I suggest having less than 2 weeks' worth of backups is not sufficient. Even just two weeks worth is minimal.

Backup copies SHOULD be stored on a separate drive, but the following is just copying from/to the local C: drive.

Your scheduler command would look something like this:
at 21:44 /every:M,T,W,Th,F cmd /c c:\123back.bat

Here's an example .BAT file:
@ filename: C:\123back.bat
@-----------------code begins---------------------
@echo off
c:
cd \
if exist 123backup goto :backexist
md 123backup
:backexist
cd 123backup

if not exist 10 goto :9
del 10 /q
rd 10

:9
if not exist 9 goto :8
ren 9 10

:8
if not exist 8 goto :7
ren 8 9

:7
if not exist 7 goto :6
ren 7 8

:6
if not exist 6 goto :5
ren 6 7

:5
if not exist 5 goto :4
ren 5 6

:4
if not exist 4 goto :3
ren 4 5

:3
if not exist 3 goto :2
ren 3 4

:2
if not exist 2 goto :1
ren 2 3

:1
if not exist 1 goto :0
ren 1 2

:0
md 1
xcopy c:\123 1 /e /i

:exit
cd \
EXIT
@-----------------code ends---------------------

You'll wind up with a subdirectory called "123backup" on the C: drive.
It will have 10 subdirectories, numbered 1 through 10.
directory 1 will always have the most current backup; directory 10 the oldest.
Determine the backup copy date & time by the directory creation date & time.

Last edited by SgtWookie; 10-17-2009 at 09:57 PM.
Reply With Quote
  #6  
Old 10-19-2009, 02:08 AM
SgtWookie's Avatar
SgtWookie SgtWookie is online now
Senior Member
 
Join Date: Jul 2007
Location: Orlando, FL USA
Posts: 8,375
Default

A more generalized approach
AT command:
AT 21:44 /every:M,T,W,Th,F cmd /c C:\backit.bat C: 123 C: DeakinU
All files in c:\123 will be copied to C:\backup\DeakinU\01 on the days specified.
There will eventually be 10 subdirectories under C:\backup\DeakinU.

@rem ---file: backit.bat --------------------------------------------------
@echo off
if \%1\==\\ goto :err
if \%2\==\\ goto :err
if \%3\==\\ goto :err
if \%4\==\\ goto :err
goto :noerr
:err
echo "%0 %1 %2 %3 %4" is not correct. Exactly 4 parameters are required.
echo Syntax:
echo "%0 source_drive: source_dir dest_drive: dest_dir"
echo Copies will be placed in the dest_drive:\backup\dest_dir directory
goto :exit
:noerr
%1
cd \
%3
if exist backup goto :backexist
md backup
:backexist
cd backup
if exist %4 goto :back2exist
md %4
:back2exist
cd %4

if not exist 10 goto :09
rd 10 /s /q

:09
ren 09 10
ren 08 09
ren 07 08
ren 06 07
ren 05 06
ren 04 05
ren 03 04
ren 02 03
ren 01 02
md 01
xcopy %1\%2 01 /c /e /i /q /h

:exit
%1
cd \
exit
@rem --- end --------------------------------------------------

Last edited by SgtWookie; 10-19-2009 at 02:16 AM.
Reply With Quote
  #7  
Old 10-19-2009, 03:02 AM
Anthony Quah's Avatar
Anthony Quah Anthony Quah is offline
Member
 
Join Date: Dec 2007
Posts: 77
Default

oh man, thank for the help..i going to try it out...
Reply With Quote
  #8  
Old 10-26-2009, 05:45 AM
Anthony Quah's Avatar
Anthony Quah Anthony Quah is offline
Member
 
Join Date: Dec 2007
Posts: 77
Default

Sgt Wookie,

I just got the program work, but I need advice how to delete the oldest folder after it reach folder "test3" because i don't want it to populate our the disk space. Need some help on this...




@ filename: C:\123back.bat
@-----------------code begins---------------------
@echo off
c:
cd \
at 15:45 /every:M,T,W,Th,F cmd/c c:\123back.bat
if exist 123backup goto :backexist
md 123backup
:backexist
cd 123backup


if not exist c:\123backup\original goto :1
ren c:\123backup\original test1

:1
if not exist c:\123backup\test1 goto :2
ren c:\123backup\test1 test2


:2
if not exist c:\123backup\test2 goto :3
ren c:\123backup\test2 test3

:3
if not exist c:\123backup\test2 goto :0
ren c:\123backup\test2 test3


:0
xcopy c:\EC_logs c:\123backup\original /e /i /y

:exit
cd \
EXIT
@-----------------code ends---------------------
Attached Images
File Type: jpg AbleGenerateFolderbyFolder.JPG (44.1 KB, 9 views)
Reply With Quote
  #9  
Old 10-26-2009, 06:39 AM
SgtWookie's Avatar
SgtWookie SgtWookie is online now
Senior Member
 
Join Date: Jul 2007
Location: Orlando, FL USA
Posts: 8,375
Default

Quote:
Originally Posted by Anthony Quah View Post
Sgt Wookie,

I just got the program work, but I need advice how to delete the oldest folder after it reach folder "test3" because i don't want it to populate our the disk space. Need some help on this...
You're doing it backwards.
You're renaming original to test1, and then right away renaming test1 to test2, and then renaming test2 to test3.

The first time you run it, you'd wind up with just an "original" subdirectory.
The next time you ran it, original would be renamed to test1, then test2, then test3, and a new "original" directory would be created.
The next time you ran it, "original would be renamed to test1, then test2, but the rename to test3 would fail because test3 already exists.

You need to deal with the oldest backup directory, test3, first - by deleting it.
Then rename test2 to test3, if test2 exists.
Then rename test1 to test2, if test1 exists. Etc.

AT 15:45 /every:M,T,W,Th,F cmd /c c:\123back.bat
The AT command should not be in the batch file.
Here's a shorter version:

@REM filename: C:\123back.bat
@REM -----------------code begins---------------------
@echo off
c:
cd \
if not exist 123backup md 123backup
cd 123backup
if exist test3 rmdir test3 /s /q
if exist test2 ren test2 test3
if exist test1 ren test1 test2
if exist original ren original test1
xcopy c:\EC_logs c:\123backup\original /e /i /y
cd \
EXIT
@REM-----------------code ends---------------------

This way, the oldest directory, test3, is removed first each time the batch file is executed, and the remaining testn directories get renamed, along with "original" to test1.

Then the "original" is created from the current C:\EC_logs directory.

Last edited by SgtWookie; 10-26-2009 at 04:29 PM.
Reply With Quote
Reply   Post New Thread

Bookmarks

Tags
,

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sleep command mr boss Embedded Systems and Microcontrollers 10 07-07-2009 06:37 AM
Plz help! tejasi.p@gmail.com Embedded Systems and Microcontrollers 0 03-14-2009 10:27 AM
LCD damaged? winson General Electronics Chat 5 02-08-2009 06:37 PM
LCD and real clock timer apiz88 Programmer's Corner 3 10-03-2008 06:39 AM
Dos mpuvdd Programmer's Corner 3 02-18-2008 06:54 PM


All times are GMT. The time now is 06:53 AM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Copyright © 2009, All About Circuits. All Rights Reserved.