how to copy large files (bigger than ~2GB)

BlitzMax Forums/BlitzMax Programming/how to copy large files (bigger than ~2GB)

Andres(Posted 2010) [#1]
Is there a way to copy files bigger than Int? I need to be able to display the progress too. Can i use kernel functions for that? or should i change the stdc.c (change all Ints to Doubles? :P) file or what?


Nate the Great(Posted 2010) [#2]
you can divide it up and use open file and write int to copy the file one 2gb piece at a time.


xlsior(Posted 2010) [#3]
Can you even read the file beyond 2GB, though?

I'd kind of expect it to lose track of its location inside of the file once you hit that barrier as well...


TaskMaster(Posted 2010) [#4]
I have a Windows solution to this problem, using the Windows API to check file sizes, and copy files.

If you want me to post it, I can, but it looks like you are looking for a Linux solution?!?!


xlsior(Posted 2010) [#5]
I'd be interested in a Windows solution...


TaskMaster(Posted 2010) [#6]
To copy a file:

Declare the function:
Extern "win32"
	Function CopyFileExW:Int(SrcFile$W, DestFile$W, CallBack:Byte Ptr, Data:Int Ptr, Cancel:Int Ptr, Flags:Int)
End Extern


Then just call it:
CopyFileExW(src, dst, Null, Null, Null, 0)

src and dst are just strings containing complete paths to the source abnd detsination of the file.

To get a filesize:

Declare the functions:
Extern "win32"
	Function CreateFileA:Int (lpFileName$Z, dwDesiredAccess:Int, dwShareMode:Int, lpSecurityAttributes:Byte Ptr, dwCreationDisposition:Int, dwFlagsAndAttributes:Int, hTemplateFile:Int)
	Function CloseHandle:Int (hObject:Int)
	Function GetFileSizeEx:Int(handle:Int, size:Long Ptr)
End Extern


Use this BMax function:
Function getFileSize:Long(file:String)
	Local out:Long = -1
	Local handle:Int = CreateFileA(file, 128, 1, Null, 3, 0, 0)
	If handle <> -1
		GetFileSizeEx(handle, Varptr out)
	End If
	CloseHandle(handle)
	Return out
End Function



xlsior(Posted 2010) [#7]
Thanks!


Azathoth(Posted 2010) [#8]
Can you even read the file beyond 2GB, though?
I wrote a filestream that can read and write 2GB+ files.

http://www.blitzbasic.com/Community/posts.php?topic=88492#1004898


xlsior(Posted 2010) [#9]
Thanks for the link, might come in handy some day.


Andres(Posted 2010) [#10]
i'm too interested in solution for windows. I'll try out the link at some point.
Too much to do with other projects at the time.