Here is an update version of the program that creates 1000 files with random line lengths for a more consistent test result:
// Project: MoveFiles
// By: Virtual Nomad, updated by SFSW/Vice 2023-01-21 to incorporate Move Mem operation and building random initial files to avoid cache interference
// Created: 2023-01-20
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "MoveFiles" )
SetWindowSize(1280,720, 0 )
SetWindowAllowResize( 0 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1280,720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetPrintSize(24)
#import_plugin FileExplore as FE
CenterWindow()
GLOBAL SourceDIR$, DestDIR$, TotalFiles
LoadPrefs()
// start by creating 100 large text files with random line lengths to avoid cache interference with test results
for i = 1 to 1000
if i=1 or mod(i,10)=0
print("Removing any old files, please wait...")
print(str(i/10)+"%")
sync()
endif
s$="raw:"+SourceDIR$+"\"+"FileTest"+str(i)+".txt"
rem remove any old residual versions of the files first
if GetFileExists(s$)=1 then DeleteFile(s$)
rem check the destination folder also
s$="raw:"+DestDIR$+"\"+"FileTest"+str(i)+".txt"
if GetFileExists(s$)=1 then DeleteFile(s$)
next i
for i = 1 to 1000
if i=1 or mod(i,10)=0
print("Building Random Files...")
print(str(i/10)+"%")
sync()
endif
rem now create the random text files
s$="raw:"+SourceDIR$+"\"+"FileTest"+str(i)+".txt"
OpenToWrite(1,s$)
for ii = 1 to 1000
ss$=spaces(random(100,200))
WriteLine(1,ss$)
next ii
CloseFile(1)
next i
TotalFiles=CountFiles(SourceDIR$)
GLOBAL FromBUT, ToBUT, CopyBUT, MoveBUT, CopyMemBUT, MoveMemBUT
FromBUT = 1 : ToBUT = 2 : CopyBUT = 3 : MoveBUT = 4
CopyMemBUT = 5 : MoveMemBUT = 6
AddVirtualButton(FromBUT,32,688,64) : SetVirtualButtonText(FromBUT,"SOURCE$")
SetVirtualButtonAlpha( FromBUT, 128 )
AddVirtualButton(ToBUT,96,688,64) : SetVirtualButtonText(ToBUT,"DEST$")
SetVirtualButtonAlpha( ToBUT, 128 )
AddVirtualButton(CopyBUT,160,688,64) : SetVirtualButtonText(CopyBUT,"COPY")
SetVirtualButtonAlpha( CopyBUT, 128 )
AddVirtualButton(MoveBUT,224,688,64) : SetVirtualButtonText(MoveBUT,"MOVE")
SetVirtualButtonAlpha( MoveBUT, 128 )
AddVirtualButton(CopyMemBUT,288,688,64) : SetVirtualButtonText(CopyMemBUT,"COPY" + CHR(10) + "MEM")
SetVirtualButtonAlpha( CopyMemBUT, 128 )
AddVirtualButton(MoveMemBUT,352,688,64) : SetVirtualButtonText(MoveMemBUT,"MOVE" + CHR(10) + "MEM")
SetVirtualButtonAlpha( MoveMemBUT, 128 )
do
If GetVirtualButtonReleased(FromBUT) then SetSource()
If GetVirtualButtonReleased(ToBUT) then SetDestination()
If GetVirtualButtonPressed(CopyBUT) then CopyFiles()
If GetVirtualButtonPressed(MoveBUT) then MoveFiles()
If GetVirtualButtonPressed(CopyMemBUT) then CopyMemFiles()
If GetVirtualButtonPressed(MoveMemBUT) then MoveMemFiles()
Print( "From: " + SourceDIR$ + " @ " + STR(TotalFiles) + " files.")
Print( "To: " + DestDIR$ )
Sync()
loop
Function LoadPrefs()
If GetFileExists("mfprefs.data")
ThisFile = OpenToRead("mfprefs.data")
SourceDIR$ = ReadLine(ThisFile)
` TotalFiles = CountFiles(SourceDIR$) ` wait until after any old files are cleared and new ones are created
FE.SetWorkingDirectory(SourceDIR$)
DestDIR$ = ReadLine(ThisFile)
CloseFile(ThisFile)
Else
SourceDIR$ = GetReadPath()
FE.SetWorkingDirectory(SourceDIR$ )
DestDIR$ = GetWritePath()
EndIf
EndFunction
Function SavePrefs()
ThisFile = OpenToWrite("mfprefs.data")
WriteLine(ThisFile, SourceDIR$)
WriteLine(ThisFile, DestDIR$)
CloseFile(ThisFile)
EndFunction
Function SetSource()
ThisDIR$ = FE.ChooseFolderDialog("Select Source Folder", "")
If ThisDIR$ <> ""
SourceDIR$ = ThisDIR$
SavePrefs()
FE.SetWorkingDirectory(ThisDIR$)
TotalFiles = CountFiles(ThisDIR$)
EndIf
EndFunction
Function SetDestination()
ThisDIR$ = FE.ChooseFolderDialog("Select Destination Folder", "")
If ThisDIR$ <> ""
DestDIR$ = ThisDIR$
SavePrefs()
EndIf
EndFunction
Function CountFiles(dir$)
ThisFolder = OpenRawFolder(dir$)
TotalFiles = GetRawFolderNumFiles( ThisFolder )
CloseRawFolder(ThisFolder)
EndFunction TotalFiles
Function CopyFiles()
TheseFiles = 0
ThisFile$ = FE.GetFirstFile("*.*")
Start# = Timer()
Repeat
FE.FileCopy(ThisFile$, DestDIR$+"\"+ThisFile$,0)
INC TheseFiles
ThisFile$ = FE.GetNextFile()
Until ThisFile$ = ""
Elapsed$ = STR(Timer()-Start#,2)
Repeat
Print( STR(TheseFiles) + " files copied.")
Print(Elapsed$)
Sync()
Until GetPointerPressed()
OpenBrowser(DestDIR$)
EndFunction
Function MoveFiles()
TheseFiles = 0
ThisFile$ = FE.GetFirstFile("*.*")
Start# = Timer()
Repeat
FE.FileMove(ThisFile$, DestDIR$+"\"+ThisFile$)
INC TheseFiles
ThisFile$ = FE.GetNextFile()
Until ThisFile$ = ""
Elapsed$ = STR(Timer()-Start#,2)
Repeat
Print( STR(TheseFiles) + " files copied.")
Print(Elapsed$)
Sync()
Until GetPointerPressed()
OpenBrowser(DestDIR$)
EndFunction
Function CopyMemFiles()
ThisFolder = OpenRawFolder(SourceDIR$)
TheseFiles = GetRawFolderNumFiles(ThisFolder)
Start# = Timer()
For x = 0 to TheseFiles
ThisFile$ = GetRawFolderFileName(ThisFolder,x)
If ThisFile$ <> ""
CreateMemblockFromFile(1,"raw:"+SourceDIR$+"\" + ThisFile$)
CreateFileFromMemblock("raw:"+DestDIR$+"\" + ThisFile$,1)
DeleteMemblock(1)
EndIf
next x
CloseRawFolder(ThisFolder)
Elapsed$ = STR(Timer()-Start#,2)
Repeat
Print( STR(TheseFiles) + " files copied.")
Print(Elapsed$)
Sync()
Until GetPointerPressed()
OpenBrowser(DestDIR$)
EndFunction
Function MoveMemFiles()
ThisFolder = OpenRawFolder(SourceDIR$)
TheseFiles = GetRawFolderNumFiles(ThisFolder)
Start# = Timer()
For x = 0 to TheseFiles
ThisFile$ = GetRawFolderFileName(ThisFolder,x)
If ThisFile$ <> ""
CreateMemblockFromFile(1,"raw:"+SourceDIR$+"\" + ThisFile$)
CreateFileFromMemblock("raw:"+DestDIR$+"\" + ThisFile$,1)
DeleteMemblock(1)
DeleteFile("raw:"+SourceDIR$+"\" + ThisFile$)
EndIf
next x
CloseRawFolder(ThisFolder)
Elapsed$ = STR(Timer()-Start#,2)
Repeat
Print( STR(TheseFiles) + " files copied.")
Print(Elapsed$)
Sync()
Until GetPointerPressed()
EndFunction
Function CenterWindow()
X = GetMaxDeviceWidth()/2.0 - GetWindowWidth()/2.0
Y = GetMaxDeviceHeight()/2.0 - GetWindowHeight()/2.0
SetWindowPosition( X,Y)
EndFunction
For me, I get pretty consistent times when running each method repeatedly. So this may be a better overall gauge of performance. I generally get in the 0.95 to 1.2 second range (few tenths slower for mem operations, so marginal difference). Caching may still get involved from time to time as occasionally, delays in retesting seem to slow down the initial delete operation significantly. But that would likely be true of any file management command, not just AGK's. Overall, all are comparatively very fast.