473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

file rename woes - want atomic operation...

no "rename" operation in C# !!!

- this has been covered in this group before, but I can't find any good
answers.

what I am trying to do is refresh the content in a file with minimum
performance impact on any read operations to that file - a common task
right....

in the unix world the way to do this is to create a temporary file with
the new content, and "rename" the temporary file to the destination
file. This works because the rename operation is atomic in the sense
that the old file is removed and the new file moved without the chance
of some other process accessing the file in between.

this operation is also fast as the rename does not actually move any of
the data on disk (it's an inode manipulation).

....I can't find how to do this in C# !

the File.Move operation is no good because it throws an exception if
the target file already exists.

File.Delete, File.Move is also no good because it is not atomic....

any ideas?

thanks,

Oli@TigerTechSoftware

Nov 2 '06 #1
1 4491
It's a well-known issue. The reason is that there is no resource manager for
the file system (your can realize your own, and we can only with u good luck
with this :))

BTW, they solve this only in Vista API and introduced this as KTM (Kernel
Transaction Manager). You can read about it there
http://msdn.microsoft.com/msdnmag/is...X/default.aspx with
sample that u noted.

And now there is nothing else better then just handing exeption (as used in
that article) in case if file exists
--
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


"sp*************@yahoo.com" wrote:
no "rename" operation in C# !!!

- this has been covered in this group before, but I can't find any good
answers.

what I am trying to do is refresh the content in a file with minimum
performance impact on any read operations to that file - a common task
right....

in the unix world the way to do this is to create a temporary file with
the new content, and "rename" the temporary file to the destination
file. This works because the rename operation is atomic in the sense
that the old file is removed and the new file moved without the chance
of some other process accessing the file in between.

this operation is also fast as the rename does not actually move any of
the data on disk (it's an inode manipulation).

....I can't find how to do this in C# !

the File.Move operation is no good because it throws an exception if
the target file already exists.

File.Delete, File.Move is also no good because it is not atomic....

any ideas?

thanks,

Oli@TigerTechSoftware

Nov 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Willem van Isselmuden | last post by:
Hello, i have this upload script, works fine, ik kan upload multiple files to my server, but i want them to be saved under a different namen on the server. My form has 4 file fields and i want...
1
by: Kashish | last post by:
Is file<<"Some string"<<endl is an atomic operation. where file is an ofstream object. If we output a string in ofstream and we provide endl after that,Can we make sure the whole string will be...
4
by: Patrick de Ridder | last post by:
This is rather elementary but I cannot find it anywhere. How do you rename a file from within a program in C# ? (In the directory I mean.) How do you delete a file from within a program in C# ?...
4
by: kevin | last post by:
Hi, I am trying to create a page so the user can browse the network, select a file and have that file name (text) inserted into our sql DB so I can build the hyperlink path later on. Here's what...
7
by: Joe HM | last post by:
Hello - I was wondering if there is a simple way of ensuring that some statements are executed as an "atomic operation". Here is what I am dealing with in a GUI ... Dim mAppDomain As...
9
by: Mark | last post by:
Hi all, This is something which has been bugging me for ages. How can I check if a file is already in use by a different program? It doesn't seem to matter which mode I pass to fopen, it will...
1
by: hardik | last post by:
can anyone tell me how i can change the filename which is going to uploaded here is a code for uploading a file <!-- #include file="clsUpload.asp" --> Set objUpload = New clsUpload If...
3
by: Bill Ross | last post by:
I am trying to do the following: * receive three image files one at a time * validate that it is a valid image type, size * as each is received, I store the image, then show the image * when...
2
by: newyorker213 | last post by:
Hello, We have files ( named in the following format ) in one of our folders: MV0001.XLS MV0002.XLS and so on WV0001.XLS WV0002.XLS
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.