Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / November 2007

Tip: Looking for answers? Try searching our database.

Delete from file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ole - 09 Nov 2007 08:41 GMT
I know that it generally isn't possible to delete a part of a file, but I'll
pop this question anyway in case there is a good idea out there:

I have a program that runs on a PDA with e.g. 32MB storage. The program
generate a file and if the file exceed 16MB I do not have the possibility to
delete a single character from the file, because I normally will have to
create a new file without the character and after that delete the original
file  ---- or what????

Thanks
Ole
Simon Hart [MVP] - 09 Nov 2007 12:15 GMT
I don't understand what you are trying to achieve. Are you saying, when the
file equals a certain size, you want to delete it?
Signature

Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com

> I know that it generally isn't possible to delete a part of a file, but I'll
> pop this question anyway in case there is a good idea out there:
[quoted text clipped - 7 lines]
> Thanks
> Ole
Paul G. Tobey [eMVP] - 09 Nov 2007 15:15 GMT
Sounds like he wants to remove a section of a file that is half the size of
the available storage.  Since you can't just cut out some bytes from the
middle, the only practical way to do it is to create a new file and copy
just the parts of the old file that you want into the new file.  However, if
the old file is half the size of the storage, that's a problem.  There's no
fix that I can think of other than to stop growing the other file sooner...

Paul T.

>I don't understand what you are trying to achieve. Are you saying, when the
> file equals a certain size, you want to delete it?
[quoted text clipped - 13 lines]
>> Thanks
>> Ole
<ctacke/> - 09 Nov 2007 15:57 GMT
The only thing I could think of is opening the file multiple times with
share access and doing some form of data "shift" using two file pointers -
essentially copying file data within the target file itself.  It could be
slow and terribly thrashy if, for example, you deleted a single byte at the
start of a 16MB file.  You'd end up copying the entire 16MB one byte at a
time to shift it.

On the plus side, at least it would work.

Signature

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com

> Sounds like he wants to remove a section of a file that is half the size
> of the available storage.  Since you can't just cut out some bytes from
[quoted text clipped - 24 lines]
>>> Thanks
>>> Ole
Ole - 09 Nov 2007 17:42 GMT
Sounds like a very useful idea and exactly what I was looking for - will try
it out.

Thanks
Ole

> The only thing I could think of is opening the file multiple times with
> share access and doing some form of data "shift" using two file pointers -
[quoted text clipped - 34 lines]
>>>> Thanks
>>>> Ole
Ole - 10 Nov 2007 10:03 GMT
I wonder what happens to the "Tale" of the file and how to tell the OS that
the file has decreased in size.? If I have a file of e.g. 10 KB in size and
I want to delete 1 KB from the middle of it, then I according to the below,
should "shift" the upper part of the file downwards until the the last byte
which is the EOF, but what happens to the last 10KB? Are there any code
snippets available?

Thanks,
Ole

> The only thing I could think of is opening the file multiple times with
> share access and doing some form of data "shift" using two file pointers -
[quoted text clipped - 8 lines]
> Join the Embedded Developer Community
> http://community.opennetcf.com
<ctacke/> - 10 Nov 2007 14:51 GMT
Simply call SetLength on the FileStream to the new length, Flush and Close.

Signature

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com

>I wonder what happens to the "Tale" of the file and how to tell the OS that
>the file has decreased in size.? If I have a file of e.g. 10 KB in size and
[quoted text clipped - 18 lines]
>> Join the Embedded Developer Community
>> http://community.opennetcf.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.