Automatically Copy From Drive to Year-Month-Day Folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Automatically Copy From Drive to Year-Month-Day Folder

#1 Post by Samir » 13 Mar 2015 09:10

I'm thinking this will need a helper program to detect media insertion, but here's the problem.

Every day, there is 1 CD and 2 Floppy disks of data that need to be archived to a hard drive. After they have been properly archived, the media needs to be erased.

I want a batch file that will detect the media (helper program may be needed for this), copy the files, compare them, and then delete them if the compare was successful. This batch will probably be run under win95/98 unless something higher is needed.

Any ideas on how to approach this appreciated. The main areas I'm unsure about are the media detection and a good algorithm to make sure the files are copied correctly before deletion.

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: Automatically Copy From Drive to Year-Month-Day Folder

#2 Post by Matt Williamson » 13 Mar 2015 09:48

You can do the insertion detection using WMIC or FSUTIL but I don't think either of them are available until Winxp. Also, where do you get those floppy disks? I thought they stopped making them a few years ago. ;)

Show an example of the file names for the second part. I recently wrote a script that does what you want almost exactly.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Automatically Copy From Drive to Year-Month-Day Folder

#3 Post by Samir » 13 Mar 2015 10:15

Matt Williamson wrote:You can do the insertion detection using WMIC or FSUTIL but I don't think either of them are available until Winxp. Also, where do you get those floppy disks? I thought they stopped making them a few years ago. ;)

Show an example of the file names for the second part. I recently wrote a script that does what you want almost exactly.
Yeah, I think those are part of xp. :( I'd rather not depend on anything in the OS though. A stand-alone exe that did the detection as part of the batch would be preferable. This would also allow it to run on some of our older win9x boxes that do small tasks like this.

I'm not sure what the source file names will be, but the copy part would be basically

Code: Select all

xcopy DRIVE:\ ARCHIVE DRIVE:\ARCHIVE\YEAR\MM\DD\ /f/r/e/s/h/k/y/d/c

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

Re: Automatically Copy From Drive to Year-Month-Day Folder

#4 Post by foxidrive » 13 Mar 2015 22:10

Samir wrote:Every day, there is 1 CD and 2 Floppy disks of data that need to be archived to a hard drive. After they have been properly archived, the media needs to be erased.

I want a batch file that will detect the media (helper program may be needed for this), copy the files, compare them, and then delete them if the compare was successful.


Are there any more copies of the files other than the ones being made on the hard drive?

I am pretty sure that Win95/98 can't erase a cd even if it is a cd-rw.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Automatically Copy From Drive to Year-Month-Day Folder

#5 Post by penpen » 14 Mar 2015 04:58

Maybe the Cdrtools suite is able to erase a cd-rw.

I've seen (unofficial) binaries of Cdrtools (in the past) even for for MS-DOS 6.22, and i assume there are (probably unofficial) releases for win95/98.

You "only" have to find these binaries, or download the sources (if still available; not tested) of the components listed at http://cdrecord.org and compile them.

penpen

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Automatically Copy From Drive to Year-Month-Day Folder

#6 Post by Samir » 14 Mar 2015 07:43

foxidrive wrote:
Samir wrote:Every day, there is 1 CD and 2 Floppy disks of data that need to be archived to a hard drive. After they have been properly archived, the media needs to be erased.

I want a batch file that will detect the media (helper program may be needed for this), copy the files, compare them, and then delete them if the compare was successful.


Are there any more copies of the files other than the ones being made on the hard drive?

I am pretty sure that Win95/98 can't erase a cd even if it is a cd-rw.
No, the files copied to the hard drive would be the only ones after the originals are erased.

I hoping that there may be an application for the win95/98 that can erase a cd, but if not, it's not a dealbreaker. Those things are cheap enough these days to not be a requirement for the batch.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Automatically Copy From Drive to Year-Month-Day Folder

#7 Post by Samir » 14 Mar 2015 08:38

penpen wrote:Maybe the Cdrtools suite is able to erase a cd-rw.

I've seen (unofficial) binaries of Cdrtools (in the past) even for for MS-DOS 6.22, and i assume there are (probably unofficial) releases for win95/98.

You "only" have to find these binaries, or download the sources (if still available; not tested) of the components listed at http://cdrecord.org and compile them.

penpen
Thank you very much for the references. I was able to search and find various different dos/windows command line ways to erase the cdrw. I haven't tested any of them yet, but they all look very promising.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Automatically Copy From Drive to Year-Month-Day Folder

#8 Post by penpen » 14 Mar 2015 13:40

You may use the autorun option of win9x to detect if a media is inserted (but you need control about the cd content).
I'm not sure if autorun is enabled, or could be enabled for fdds, but this is possible for cd/dvd/.... .

Just create a "autorun.inf" in the root of the cd similar to this (Edit: corrected the code):

Code: Select all

[autorun]
open=C:\Windows\system32\cmd.exe ... args... C:\your\backup\batch.bat

You also may add something like a "gatekeeper" environment variable to prevent the call of the batch file in most other pc's:
cmd.exe ... "if defined backupdevice C:\your\backup\batch.bat"

Another option is, to test for a specific file on the disk, when you manually start your backup batch.

If you need to create a current date folder you may do something like this:

Code: Select all

@echo off
>return.txt echo:
>Current.bat echo:@set today=%%4
type return.txt | >toDate.bat date
call toDate.bat

del toDate.bat
del Current.bat
del return.txt

echo today=%today%

You may need to adjust the the name "Current.bat" if the first word of the "date" command output changes:

Code: Select all

Current date is Mon 16.03.2015
Enter new date (dd-mm-yy):


penpen

Edit 1: I've corrected the line ">Current.bat echo:@echo:%%4": "@echo" -> "set today="
Edit 2: Added the last section.
Last edited by penpen on 15 Mar 2015 18:59, edited 1 time in total.

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

Re: Automatically Copy From Drive to Year-Month-Day Folder

#9 Post by foxidrive » 14 Mar 2015 16:11

Samir wrote:
foxidrive wrote:Are there any more copies of the files other than the ones being made on the hard drive?
No, the files copied to the hard drive would be the only ones after the originals are erased.


Oh, ok. They must be unimportant files then.

But don't mind me, I'm a bit of a backup nazi.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Automatically Copy From Drive to Year-Month-Day Folder

#10 Post by Samir » 15 Mar 2015 07:56

penpen wrote:You may use the autorun option of win9x to detect if a media is inserted (but you need control about the cd content).
I'm not sure if autorun is enabled, or could be enabled for fdds, but this is possible for cd/dvd/.... .

Just create a "autorun.inf" in the root of the cd similar to this:

Code: Select all

[autorun]
open=C:\Windows\system32\cmd.exe ... args... C:\your\backup\batch.bat

You also may add something like a "gatekeeper" environment variable to prevent the call of the batch file in most other pc's:
cmd.exe ... "if defined backupdevice C:\your\backup\batch.bat"

Another option is, to test for a specific file on the disk, when you manually start your backup batch.

If you need to create a current date folder you may do something like this:

Code: Select all

@echo off
>return.txt echo:
>Current.bat echo:@echo:%%4
type return.txt | >toDate.bat date
call toDate.bat

del toDate.bat
del Current.bat
del return.txt

echo today=%today%


penpen
I won't be able to put anything on the source media since it will be coming from another system. That's an interesting batch for the date.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Automatically Copy From Drive to Year-Month-Day Folder

#11 Post by penpen » 15 Mar 2015 19:03

I noticed that my date batch was wrong and corrected it:
The environment variable "today" should have been set to the date, instead of echoing it in Current.bat.

penpen

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Automatically Copy From Drive to Year-Month-Day Folder

#12 Post by Samir » 16 Mar 2015 09:38

penpen wrote:I noticed that my date batch was wrong and corrected it:
The environment variable "today" should have been set to the date, instead of echoing it in Current.bat.

penpen
That makes more sense now. I was having some trouble following the batch, but know that you know a lot more about batch than I do, so I was assuming it would work.

Post Reply