By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,501 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,501 IT Pros & Developers. It's quick & easy.

Delete a file using copy to bit bucket

P: n/a
Is it possible to delete a file by copying it to the "bit bucket" or
"null device"?

Back in my youth when I live in VMS-land you could delete a file by
copying it to NL:

==========

I have written a windows service as part of an interface between two
different systems. The first system will write output into a file in a
shared folder. The server will detect the new file(s) and process
them.

If the second system is updated successfully the file is moved to a
"success" folder and if not it is move to a "failure" folder.
Eventully there will be a huge number of files in the success folder.
The source, success and failure folders are specified in a config file.
Once the user is satisified that the process is working they would
like to just delete the successfull files but still keep the option to
return to moving them to the success folder. The easiest way to do
this, without any code changes, is to just specify the success folder
as the "bit bucket" or "null device", then the copy would just send the
file off into the ether.

Mike Buchanan

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
No.

Copy does just that, copy the contents. I am so glad the coping a file does
not remove it.
<Ne**@InsightfulMES.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Is it possible to delete a file by copying it to the "bit bucket" or
"null device"?

Back in my youth when I live in VMS-land you could delete a file by
copying it to NL:

==========

I have written a windows service as part of an interface between two
different systems. The first system will write output into a file in a
shared folder. The server will detect the new file(s) and process
them.

If the second system is updated successfully the file is moved to a
"success" folder and if not it is move to a "failure" folder.
Eventully there will be a huge number of files in the success folder.
The source, success and failure folders are specified in a config file.
Once the user is satisified that the process is working they would
like to just delete the successfull files but still keep the option to
return to moving them to the success folder. The easiest way to do
this, without any code changes, is to just specify the success folder
as the "bit bucket" or "null device", then the copy would just send the
file off into the ether.

Mike Buchanan

Nov 17 '05 #2

P: n/a
Ne**@InsightfulMES.com wrote:
Is it possible to delete a file by copying it to the "bit bucket" or
"null device"?

<snip>

Just a comment to your service. I've implemented several such services
in various ways and one thing I've found is that it's impossible for me
to guarantee that the system will work in all situations.

There could be a multitude of sources for errors that can crop up and at
some point you're going to loose a file, or try to figure out wether a
file was processed or not.

I found that by always moving the file to a "successful" directory after
processing it, or an "error" directory in case of problems, the user
always knows that whatever happens (network problems, database
crash/rollback/restore, disk full, etc.) they can always find their
files and just move them back into the processing directory to reprocess
them.

The problem I was left with then was that this directory quickly filled
up, but after a time, old files are no longer interesting nor necessary
so I just added code to the service to take a look in this directory
from time to time and delete all files older than X days (14 in most
cases) to keep its size down.

In any case, a simple change for your program would be that your program
accepts an empty directory name as the successful target, and in that
case the program just uses File.Delete to remove the file instead of
File.Move.

--
Lasse Vågsæther Karlsen
http://www.vkarlsen.no/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Nov 17 '05 #3

P: n/a
Hi,
Back in my youth when I live in VMS-land you could delete a file by
copying it to NL:
Copying or moving it?
I never worked in VMS, but in *NIX you could do that, move the file th
/dev/null

If the second system is updated successfully the file is moved to a
"success" folder and if not it is move to a "failure" folder.
Eventully there will be a huge number of files in the success folder.
The source, success and failure folders are specified in a config file.
Once the user is satisified that the process is working they would
like to just delete the successfull files but still keep the option to
return to moving them to the success folder. The easiest way to do
this, without any code changes, is to just specify the success folder
as the "bit bucket" or "null device", then the copy would just send the
file off into the ether.

Mike Buchanan


Well, your problem could be solver with a simple config var and an if
construction:

if ( Configuration.AppSettings["DeleteSuccess"] == "yes" )
{
// proceed to delete it.
}
I have a similar situation, only that I keep the files a number of days, I
delete them after a certain number of days.

does that solve your problem ?
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.