![]() |
| ||
| Check the size of a file I am trying to check the size of a file with this code. The file is named "OneFile.txt" and is of the size 230 kb. The MessageBox will show the number 37. If I change the file so it will be 460 kb instead, still the messageBox will show the number 37. I am not sure if I have missed something here ? I beleive I am not checking the size of the file below. I think I checking the string ? std::string path = ""; |
| ||
| Re: Check the size of a file 1) file size is an unsigned integer not a double. 2) >> double filesize = path.size(); All that is doing is getting the number of characters in the string, not the file size Here is how to get the file size size_t fileSize = 0; There are a couple other ways to get it, such as calling the stat() function. |
| ||
| Re: Check the size of a file I understand. This is the first time I am trying to do something like this. I have rewritten this code a little bit as I am writing this for a buttonControl. I have taken if(infile.is_open()) away as seen because when having this I received the size of: 0. I am not sure if this was okay to do ? My file is 230 kb. The messageBox will show this numer: 4294967295 Have I missed something ? size_t fileSize = 0; |
| ||
| Re: Check the size of a file >>I have taken if(infile.is_open()) away as seen because when having this I received the size of: 0. I am not sure if this was okay to do ? Don't do that. If is_open() fails that means the file could not be opened for some reason. And in that case all other fstream functions will fail too. You need to find out why the file can not be opened. >>Getsize2 = Getsize.str(); You don't need Getsize2 string. String^ sizeee = gcnew String(GetSize.str()); |
| ||
| Re: Check the size of a file Yes ofcourse, I forgot to write .txt in the end of the path. I did it in the post but not in my code. Now it works. :) string path = string path = "C:\\Folder1\\Folder2\\OneFile.txt"; |
| All times are GMT -4. The time now is 3:21 am. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC