Page 1 of 1
"Save as" dialog box
Posted: Wed Sep 27, 2023 4:28 pm
by jak64
Hello all,
In a Purebasic program, upon clicking a button, I want the "Save As" dialog box to appear in order to choose where I want to save a file.
I couldn't find a matching gadget!
Thank you for your help
Re: "Save as" dialog box
Posted: Wed Sep 27, 2023 4:37 pm
by Axolotl
what about SaveFileRequester()
Code: Select all
StandardFile$ = "C:\autoexec.bat" ; set initial file+path to display
; With next string we will set the search patterns ("|" as separator) for file displaying:
; 1st: "Text (*.txt)" as name, ".txt" and ".bat" as allowed extension
; 2nd: "PureBasic (*.pb)" as name, ".pb" as allowed extension
; 3rd: "All files (*.*) as name, "*.*" as allowed extension, valid for all files
Pattern$ = "Text (*.txt)|*.txt;*.bat|PureBasic (*.pb)|*.pb|All files (*.*)|*.*"
Pattern = 0 ; use the first of the three possible patterns as standard
File$ = SaveFileRequester("Please choose file to save", StandardFile$, Pattern$, Pattern)
If File$
MessageRequester("Information", "You have selected following file:"+Chr(10)+File$, 0)
Else
MessageRequester("Information", "The requester was canceled.", 0)
EndIf
Re: "Save as" dialog box
Posted: Wed Sep 27, 2023 5:24 pm
by jak64
Hello Axolotl,
Actually, I expressed myself badly:
I have a lot of videos on an external drive. I wrote a program that allows you to display them, search them, read them, etc., and I want, when I select one in a ListIconGadget, to be able to copy it to a USB stick or other external disk, etc...
Re: "Save as" dialog box
Posted: Wed Sep 27, 2023 5:47 pm
by Quin
Use PathRequester() and CopyFile().
Re: "Save as" dialog box
Posted: Wed Sep 27, 2023 6:43 pm
by jak64
Hello Quin,
I applied what you wrote and it's exactly what I wanted.
Thank you all for your help
Re: "Save as" dialog box
Posted: Thu Sep 28, 2023 9:56 am
by jak64
Hello everyone,
I applied the instructions given by Quin in my program and it works as I want.
But, for copying a video it can take a while (especially if it's on a USB stick), I would like to show a copy progress bar. However, I don't know how to know how long the copy will take!
To do this, I need to know the size of the video but also the data transfer rate when copying!
Do you know if this is possible?
Thank you for your help
Re: "Save as" dialog box
Posted: Thu Sep 28, 2023 12:50 pm
by Mindphazer
You can check this thread :
viewtopic.php?t=74835
Re: "Save as" dialog box
Posted: Thu Sep 28, 2023 1:20 pm
by Janni
The precision level on most progress bars is about as accurate as a weather forecast from a fortune cookie.
If task cannot be done in the background, one advice is to have simple animated spinner just showing "please wait"

Re: "Save as" dialog box
Posted: Thu Sep 28, 2023 3:42 pm
by Quin
Yeah, honestly don't worry about accuracy too much, as long as the users know something is happening. A really simple solution would just be to divide the file size by 100, and use that to tell when to increase your progress bar.
Re: "Save as" dialog box
Posted: Thu Sep 28, 2023 4:09 pm
by jak64
Thank you all, I will test the different codes that I found with the link that Mindphazer gave me
See you
Re: "Save as" dialog box
Posted: Sun Oct 01, 2023 1:21 pm
by jak64
Hello everyone,
I adapted the netmaestro code that I found with the link Mindphazer gave me and integrated it into my program. It works really well:
I'll try to write a little example code and post it on the forum.
Now I have another question:
When I copy videos to a USB stick (with the netmaestro code), when the stick does not have enough space, the code only copies part of the video, which is not correct and does not 'indicates no error!
Question: can we, with Purebasic or an API, know the available space on a USB key (or an external disk)?
Thank you for your help
Re: "Save as" dialog box
Posted: Sun Oct 01, 2023 1:36 pm
by Marc56us
jak64 wrote: Sun Oct 01, 2023 1:21 pm
Question: can we, with Purebasic or an API, know the available space on a USB key (or an external disk)?
From
RSBasic API list (Strings translated)
Code: Select all
EnableExplicit
Define lpFreeBytesAvailable.q
Define lpTotalNumberOfBytes.q
Define lpTotalNumberOfFreeBytes.q
GetDiskFreeSpaceEx_("C:\", @lpFreeBytesAvailable, @lpTotalNumberOfBytes, @lpTotalNumberOfFreeBytes)
Debug "Free space : " + Str(lpFreeBytesAvailable/1024/1024/1024) + " GB"
Debug "Space used : " + Str((lpTotalNumberOfBytes-lpFreeBytesAvailable)/1024/1024/1024) + " GB"
Debug "Total space : " + Str(lpTotalNumberOfBytes/1024/1024/1024) + " GB"

Re: "Save as" dialog box
Posted: Sun Oct 01, 2023 2:09 pm
by blueb
Question: can we, with Purebasic or an API, know the available space on a USB key (or an external disk)?
This is very old, but maybe this will help...
Code: Select all
Procedure.s GetDiskSpace(DriveLetter.s)
; ------------ Get Disk Space by Timo Harter (Freak) -------
;
; Works even with high values (up to 2097152 GB)
; Returns values in MegaByte
;
; Useage: GetDiskSpace("c:\")
; ----------------------------------------------------------
drive.s = DriveLetter
Structure Quad2
L1.l
L2.l
EndStructure
GetDiskFreeSpaceEx_(@drive, FB.Quad2, TB.Quad2, TFB.Quad2)
TB.Quad2\L1>>20
TB.Quad2\L2<<12
TotalMB.l = TB.Quad2\L1 + TB.Quad2\L2
TFB.Quad2\L1>>20
TFB.Quad2\L2<<12
FreeMB.l = TFB.Quad2\L1 + TFB.Quad2\L2
UsedMB.l = TotalMB - FreeMB
MessageRequester("Disk Size","Space Total: "+Str(TotalMB)+" MB"+Chr(13)+"Space Free: "+Str(FreeMB)+" MB"+Chr(13)+"Space Used: "+Str(UsedMB)+" MB",0)
;End
EndProcedure
;===================================================================
DriveLetter.s = "c:\"
Debug GetDiskSpace(DriveLetter.s)
Re: "Save as" dialog box
Posted: Sun Oct 01, 2023 3:09 pm
by jak64
Thank you Marc56us and blueb for your help.
I used Marc56us' code and it works great.
See you