Read a locked file.
-
Does anyone know how to read a file that has been locked by the os? I want to open a file and retrieve its contents. It is already open by another program though. I can't seem to get it open. I don't need to change any data, just read the file. I know that this is possible, as I have seen other programs and editors that are capable of this. I am assuming I have to use c++ for this, but c# would be OK also.
What mode did the OS open the file with? What mode are you using? If the OS opened with "share none," you won't even be able to read the file.
-
What mode did the OS open the file with? What mode are you using? If the OS opened with "share none," you won't even be able to read the file.
I don't know the mode the os used. How can I find out? The file I want to read is a sql server transaction log file. I know that this is possible as I have seen products that will do this, I just don't know how. I have only tried to open the file with c#'s System.IO binary reader for now. I haven't looked at c++ yet. I figured that I would though.
-
Does anyone know how to read a file that has been locked by the os? I want to open a file and retrieve its contents. It is already open by another program though. I can't seem to get it open. I don't need to change any data, just read the file. I know that this is possible, as I have seen other programs and editors that are capable of this. I am assuming I have to use c++ for this, but c# would be OK also.
If you are using CFile then use: modeRead | shareDenyNone. This will work if the file isn't opened for shareDenyNone access. This is what I do in ED (see sig). You may want to see if you can open the file using ED. It should open in "view" mode. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program
-
If you are using CFile then use: modeRead | shareDenyNone. This will work if the file isn't opened for shareDenyNone access. This is what I do in ED (see sig). You may want to see if you can open the file using ED. It should open in "view" mode. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program
-
jspano wrote: It did open in ED. So I will try to open it with cfile You don't need to use CFile. All of the file open functions support the same options. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program
-
jspano wrote: It did open in ED. So I will try to open it with cfile You don't need to use CFile. All of the file open functions support the same options. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program
-
Thanks. Can you suggest the one that is most optimal for performance? The best solution would be to open the file and somehow put the bytes into a managed FileStream or ByteReader etc in .Net.
Sorry but I'm not using .Net. If you are only interested in reading the file then I'd like at using a simple memory mapped file. It will also depend on what you want to do with the file, how big it can be etc. Do you need fast random acces to lines within the file etc. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program
-
Sorry but I'm not using .Net. If you are only interested in reading the file then I'd like at using a simple memory mapped file. It will also depend on what you want to do with the file, how big it can be etc. Do you need fast random acces to lines within the file etc. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program
basically I would need to read from start to finish the whole file into memory. This might not work always though, since the files could be huge. Up to say 100megs or more. What techniques do programs like your or word do for large files? as the user scrolls around go get more data? Thanks
-
basically I would need to read from start to finish the whole file into memory. This might not work always though, since the files could be huge. Up to say 100megs or more. What techniques do programs like your or word do for large files? as the user scrolls around go get more data? Thanks
ED uses a propriety database style system where it has instant access to any line and lines can grow or shrink, be deleted or inserted as required (ie. be edited). If you just need to read the file then I'd definitely use a memory mapped file (mmf). You could build a simple STL vector<> with pointers to the start of each line. Have a look at the article here on CP on PugXML where you will see code I've added to read the XML file using mmf. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program
-
Does anyone know how to read a file that has been locked by the os? I want to open a file and retrieve its contents. It is already open by another program though. I can't seem to get it open. I don't need to change any data, just read the file. I know that this is possible, as I have seen other programs and editors that are capable of this. I am assuming I have to use c++ for this, but c# would be OK also.
I am not sure if you know that it is in fact locked by the OS (I assume you realy do not know). Try opening it with FILE_SHARE_READ. There are very few instances when you will be denied this access, the main reason is for security on WinNT/Win2000/WinxP. Of course if this is not a system level (kernal-level) file then there is a very good possiblity that the program that has it open is greedy and does not want to share reading privaliges why it has the file open. At the minimum, give Me/Us a code snippet of how you are atempting to open the file. Trust in the code Luke. Yea right!