Hi all,

Lets say Program A had opened a AAA.txt and had finished writing to it but didnt closed it as it is waiting for another patch of data to be written in around 1 mins or so.

So in between the 1mins times can Program B copy its content and after copying delete all the content in AAA.txt?

Note: I can only make changes in the code for Program B but not for Program A.

Recommended Answers

All 10 Replies

Member Avatar for jencas

You have to specify the appropriate access rights when opening the file.

Yes, I guess you can
use ofstream in program B
and ifstream in program A *I guess*

hope that will help
Peace.. :)

New thing come on mind,

your program (program A) should save the file first so that program B, can read the whole file after updating it

you can save the new data in program A after each step :)

>>you can save the new data in program A after each step

I guess he said program A is not in his hands.

>>you can save the new data in program A after each step

I guess he said program A is not in his hands.

Well, unless he can't control program A, then he can't!

because program A as I said needs to save the data in the file directly after any changes, so that program B, will use the new data in the file

Otherwise, program B will use only the old data in the file *without the updates from program A*


Hope that's clear :)

Most files that are opened for writing are opened for exclusive use -- that denys write access by other programs and processes, and sometimes denys read access too.

So in between the 1mins times can Program B copy its content and after copying delete all the content in AAA.txt?

No. Program A has the file open for writing, which will deny program B from opening it for write too so that it can delete the file contents.

I wrote 2 programs. 1 prog constantly rights a file. 1 program reads the content & finnaly tries to delete the file. I run the first program & then the second. the second was able to get the data from the file( without updated records) but as AD said the prog was not able to delete it.

Thanks to all who reply,

Thanks Prabakar for trying it out.

Tomorrow i test it out and tell you guys the outcome...

Good Luck :)

I wrote 2 programs. 1 prog constantly rights a file. 1 program reads the content & finnaly tries to delete the file. I run the first program & then the second. the second was able to get the data from the file( without updated records) but as AD said the prog was not able to delete it.

the second program cannot delete the file because the file is still open in the first program.

you need to stop the first program from 'constantly writing' and close the file before deleting.

this is similar to trying to delete a word document that is open and you get the error that say's you can't delete a file that's being used etc...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.