|
Post by crb2189 on Apr 8, 2018 2:34:08 GMT
Is it possible to copy a file like a jpg to a new location?
Also is there a way to search the old conforums posts? I could see some of the old posts by googling but couldn't find a way to search on the site.
|
|
|
Post by Rod on Apr 8, 2018 8:41:41 GMT
Where do you want to move the .jpg to? If it is here then you can either use the link to the online .jpg or upload it. There are tag buttons at the top of our message boxes one of which is for images. Only use the online link if it will persist, other wise upload it.
If you have the file then just browse to it during the upload dialog. If you just want to copy an image you see online then right click on it and choose save picture as, save it on your PC.
We are not sure yet how to make the old content available, we have the data its just deciding how to give folks access. We have a lot happening right now, the Wiki is changing as well so bear with us. In the meantime just post any questions you have. There are lots of clever members that will help you.
|
|
|
Post by crb2189 on Apr 8, 2018 11:55:04 GMT
Sorry rod, wasn’t clear with the fact I was asking so separate questions.
With just basic is it possible to copy a file to a new location with a program?
I have a folder with like 10k jpg files. Is it possible to have the user enter the name of the file they want to copy to a new folder and then do it with code so they don’t have to search and copy paste each individually? I think I’ve seen you can use the name as function to move a file but wasn’t sure if that would work right if I want a copy
|
|
|
Post by Rod on Apr 8, 2018 13:49:32 GMT
Liberty can browse for folders using API. This requires the user selects a file in the source folder and pretends to save a file in the destination folder. Bit quirky but see if it suits. BEWARE it will copy all .jpg in the source to the destination. If you just want a file at a time just work with the file the user clicked on.
dim info$(10, 10)
'get the source directory by clicking on a any .jpg within it
filedialog "Open Image Directory", "*.jpg", fileName$
p=len(fileName$)
p$=""
while p$<>"\" and p>0
p$=mid$(fileName$,p,1)
p=p-1
wend
sourceName$=left$(fileName$,p)+"\"
'get the destination directory by pretending to save the file there
filedialog "Save Image Directory", "image.jpg",fileName$
p=len(fileName$)
p$=""
while p$<>"\" and p>0
p$=mid$(fileName$,p,1)
p=p-1
wend
destinationName$=left$(fileName$,p)+"\"
'now work through the .jpg in the source
files sourceName$, "*.jpg", info$()
n=val(info$(0, 0)) 'the qty of files found
for c=1 to n
f$=info$(c,0) ' the file name
open sourceName$+f$ for input as #1
open destinationName$+f$ for output as #2
p$=input$(#1,lof(#1))
#2 p$;
close #1
close #2
next
wait
|
|
stumpy
Member in Training
Posts: 66
|
Post by stumpy on Apr 19, 2018 15:45:45 GMT
Obviously I am myself a novice! - From within a JB program the 'run' function could be used to employ a Windows program such as e.g. Paint for graphics files, or Wordpad for text, see wiki justbasic.wikispaces.com/BB___RUN#RUN-Useful%20Functions- also see justbasic.wikispaces.com/BB___NAME_AS which may be relevant. - and in JustBasic there is also a function for loading and saving bmp files so, in case it might be of any interest, here is a bit of code which seems to work ok. The demo code does require a *.bmp file to be in the place from which the prog is run (default directory), so it can load it for renaming and saving back to the same directory. (I think that Loading and Saving from/to Other Places could be done by (temporarily) changing the value of defaultDIR. This has not been implemented but, if wanted, that method could be included.) 'BMP COPIER4
foregroundColor$ = "black" WindowWidth = DisplayWidth WindowHeight = DisplayHeight
statictext #main.statictext1, "To View Files, Press Button:", 40, 32, 145, 20 button #main.displayfiles, "View Folders/Bmps", [showfiles], UL, 188, 25, 112, 30
statictext #main.statictext2, "LOADING BMP", 188, 80, 80, 20 statictext #main.statictext3, "============", 188, 92, 80, 20
statictext #main.statictext4, "ENTER name of bmp file to load:", 20, 120, 167, 20 TEXTBOX #main.loadname, 188, 114, 291,30
'----------------not yet implemented: --------------- statictext #main.statictext5, "ENTER Path from which to load:", 20, 153, 167, 20 statictext #main.statictext6, "(Leave as Default until implemented)", 10, 169, 175, 20 '----------------------------------------------------
statictext #main.statictext7, "Press Button to load:", 72, 198, 110, 20 TEXTBOX #main.loadpath, 188, 154, 291,29 button #main.loadbmp, "LOAD BMP from Disc", [loadBMP], UL 188, 190, 112, 30
'----------------------------------------------------- statictext #main.statictext8, "SAVING BMP", 188, 256, 80, 20 statictext #main.statictext9, "===========", 188, 268, 80, 20
statictext #main.statictext10, "ENTER ~new~ Name for Save:", 25, 286, 157, 20 statictext #main.statictext11, "(Pro Tem. Save is into Default path)", 12, 302, 172, 20 TEXTBOX #main.savename, 188, 288, 292, 29
statictext #main.statictext12, "( For an alternative Save Path the Textbox would be here )", 192, 330, 300, 20
statictext #main.statictext13, "Press Button to save:", 70, 362, 110, 20 button #main.savebmp, "SAVE BMP to Disc", [saveBMP], UL 188, 355, 103, 30 statictext #main.statictext14, "(currently just using the default path)", 305, 360, 200, 20
nomainwin open "BMP Copier" for window_nf as #main print #main, "trapclose [quit]"
[start]'clear the stored flag stored$ = ""
[startstored] 'keep bmp in store, for copying to another new name if required print #main.loadpath, " (Default)" wait
'-------------------
[showfiles] filedialog "View Folders", "c:\basic\*.bmp", selectedFile$ wait goto [start]
'-------------
[loadBMP] print #main.loadname, "!contents? loadname$" 'string variable loadname$ will contain the name of the file to load
print #main.loadpath, "!contents? loadpath$" 'until implemented:- 'if string is not empty, the save will stopped because alternate path has not been implementd If loadpath$ <> " (Default)" then notice "cancelled because an alternative path has not been implemented" goto [start] end if
If loadname$ = "" then notice "cancelled because No name has been entered" goto [start] end if
'The LOADBMP COMMAND CAN BE EMPLOYED HERE 'format is: LOADBMP "name", "filename.bmp" 'this loads a standard Windows *.BMP bitmap file on disk into Just BASIC. 'The "name" is a string chosen to describe the bitmap as loaded by JB, 'and the "filename.bmp" is the path/name of the bitmap file on disc. 'This assumes that the JB parameter 'defaultDIR' has not been changed, which could be done but can lead to confusion! 'and, by default, would be within the directory from which the program has been run
LOADBMP "bmpstored", loadname$ + ".bmp" stored$ = "stored" '- then a notice to say what bmp has been loaded notice "bmp '" + loadname$ + "' has been loaded and stored"
goto [startstored]
'-------------------
[saveBMP] print #main.savename, "!contents? savename$" 'string variable saveload$ will contain the 'full path' for the save
'if string is empty, the save will stopped, instead of being made to the DefaultDir$ If savename$ = "" then notice "cancelled because a ~New~ name has not been entered" goto [startstored] end if
If stored$ = "" then notice "cancelled because a bmp file is not loaded" goto [start] end if
'The COMMAND CAN NOW BE EMPLOYED HERE: BMPSAVE "bmpName", "filename.bmp" '- but, Until the entry of a full path is implemented, only "Default" will be accepted" BMPSAVE "bmpstored", savename$ + ".bmp" '- then a notice to say bmp has been saved?
notice "Saved" + chr$(13) + "bmp '" + loadname$ + "', has been saved as:-" + chr$(13) + chr$(13) + "'" + savename$ + "'" + chr$(13) + chr$(13) + "- to the default path" print #main.savename, "" 'clear text box for New Name to be saved goto [startstored] 'keep bmp in store, for copying to another new name if required
'---------------------------
[quit] confirm "Do you want to quit BMP Copier ?"; quit$ if quit$ = "no" then wait
if stored$ <> "" then UNLOADBMP "bmpstored" close #main end
|
|
stumpy
Member in Training
Posts: 66
|
Post by stumpy on Apr 21, 2018 6:43:26 GMT
crb2189, I have not tried it out but after all it looks as if just 'filedialog' itself may provide exactly what you wanted. justbasic.wikispaces.com/BB___FILEDIALOGSyntax: filedialog titleString, templateString, receiverVar$ ParameterstitleString- Used to label the dialog window. If the title-bar has the word "save" in it, then the SAVE type dialog window is used, and the approval button will say "Save". If "open" is used in the title instead of "save", then the dialog will be an OPEN file type with a button which says "Open". Examples: Open Save Save As templateString- Uses standard Windows "*" wild-card character to filter the types of files that are displayed. Multiple file types can be displayed if separated by a semicolon. An empty string ("") will display all file types. Examples: "*.*" ' displays all file types and names "*.bas" ' displays all files of type "bas" "*.txt;*.dat" ' displays all "text" and "dat" files receiverVar$ - In an Open file dialog, the name and full path of the selected file is placed in receiverVar$ Examples:Open
'Open any file filedialog "Open", "*.*", fileName$ Save'Save a text file fileName$ = "good.txt" filedialog "Save my file as...", "*.txt", fileName$ Cancel' Trapping an empty variable on Cancel filedialog "Open text file", "*.txt", fileName$ if fileName$ = "" then notice "No file chosen" end
|
|
|
Post by Rod on Apr 21, 2018 7:43:00 GMT
It is the last section of the code I posted that copies the file. You will see that I input it to a variable then print that variable to the new file name. The NAME command renames the file which was not wanted. So the file needed copied. There are many dos commands to do such copying but they are not really part of Just BASIC
|
|
stumpy
Member in Training
Posts: 66
|
Post by stumpy on Apr 21, 2018 10:53:15 GMT
Hi Rod
With JustBasic, having failed to deal with copying JPG myself, also then using just 'filedialog', I tried the code you posted.
Did I get it right that it was for LB, but not JB?
BMP Copier4 seemed to work ok. Maybe a cincidence but it seems that, Since running that code, I get this error log:-
Error log timestamp Saturday 21/04/18 12:30:00
Runtime error: system primitive failed
Error(Exception)>>defaultAction Error(Exception)>>activateHandler: <anUndefinedObject> Error(Exception)>>handle Error(Exception)>>signal Error class(Exception class)>>signal: <'system primitive fai...'> BasicProgram(Object)>>error: <'system primitive fai...'> BasicProgram>>terminateRun: <anError> [] in BasicProgram>>errorHandlerBlock ExceptionHandler>>evaluateResponseBlock: <aBlockClosure> for: <anError> [] in ExceptionHandler>>handle: ProtectedFrameMarker(BlockClosure)>>setUnwind: <aBlockClosure> BlockClosure>>invisibleEnsure: <aBlockClosure> ExceptionHandler>>handle: <anError> ExceptionHandler>>findHandler: <anError> Error(Exception)>>activateHandler: <anExceptionHandler> Error(Exception)>>handle Error(Exception)>>signal Error class(Exception class)>>signal: <'system primitive fai...'> ByteArray class(Object)>>error: <'system primitive fai...'> ByteArray class(Object)>>primitiveFailed ByteArray class(Behavior)>>new: <29942784> Bitmap>>getDIBits Bitmap>>outputToFileStream: <aFileStream> Bitmap>>outputToFile: <'ed 8x32 copy.bmp'> BasicProgram>>bmpSave: <aBasicStringContext> with: <aBasicDoubleParameterContextHolder> [] in BmpSaveCommand>>using: [] in BasicProgram>>begin ExceptionHandler>>evaluateProtectedBlock: <aBlockClosure> [] in ExceptionHandler>>activateDuring: ProtectedFrameMarker(BlockClosure)>>setUnwind: <aBlockClosure> BlockClosure>>invisibleEnsure: <aBlockClosure> ExceptionHandler>>activateDuring: <aBlockClosure> ExceptionHandler class>>handle: <anError class> with: <aBlockClosure> during: <aBlockClosure> BlockClosure>>on: <anError class> do: <aBlockClosure> BasicProgram>>begin BasicProgram>>gotoAndIfStoppedBegin: <'[saveBMP]'> BasicProgram>>handlerName: <'[saveBMP]'> evaluate: <aBlockClosure> callParameters: <anOrderedCollection> BasicProgram>>submitHandlerName: <'[saveBMP]'> evaluate: <aBlockClosure> callParameters: <anOrderedCollection> BasicProgram>>submitHandlerName: <'[saveBMP]'> callParameters: <anOrderedCollection> LibButton>>click BasicWindow>>click: <aLibButton> LibButton(Button)>>click: <aLibButton> Message>>perform Message>>evaluate LibButton(Object)>>triggerEvent: <#clicked> LibButton(Button)>>triggerClickedEvent LibButton(Button)>>notifyClicked: <66248> LibButton(Object)>>perform: <#notifyClicked:> with: <66248> LibButton(ControlPane)>>asyncControlEvent: <0> with: <66248> Message>>perform
|
|
|
Post by Rod on Apr 21, 2018 13:59:38 GMT
No it works perfectly well in Just BASIC, that's what I wrote it for. I just tested again and the code copies all the image files without error.
The error log you post seems to imply you are copying a 29Mb .bmp? Neither do I have a [saveBMP] button. Can we see the code you are running. What is the image file you are copying, path/filename.ext and what size is it.
|
|
|
Post by carlgundel on Apr 21, 2018 14:50:00 GMT
ByteArray class(Object)>>primitiveFailed ByteArray class(Behavior)>>new: <29942784> Bitmap>>getDIBits Bitmap>>outputToFileStream: <aFileStream> Bitmap>>outputToFile: <'ed 8x32 copy.bmp'> I think that the image you are trying to save is too large (29,942,784 bytes), and Just BASIC chokes when trying to convert it to a DIB. -Carl
|
|
stumpy
Member in Training
Posts: 66
|
Post by stumpy on Apr 22, 2018 7:23:18 GMT
No it works perfectly well in Just BASIC, that's what I wrote it for. I just tested again and the code copies all the image files without error. The error log you post seems to imply you are copying a 29Mb .bmp? Neither do I have a [saveBMP] button. Can we see the code you are running. What is the image file you are copying, path/filename.ext and what size is it. Rod, Thanks very much. When it worked it was indeed a much smaller file, but when it failed it probably was 29Mb, which explains the crash, as Carl has also pointed out in his post. It was 'BMP Copier4', as posted above. Will revise the code and post it later as V5. In that demo the path was limited to the one where the .bas was 'installed', (but if there ever were to be a final version, then the path would be for the user to define). filename could only have extension '.bmp' Carl, Thanks for that. May I ask what is the upper limit please?
|
|
|
Post by Stefan Pendl on Apr 22, 2018 7:53:38 GMT
I would not use LOADBMP and BMPSAVE for copying, since this will try to handle the image in memory. Only copy the image without making it available in JB.
open SourceFile$ for input as #original open DestFile$ for output as #copy print #copy, input$(#original, lof(#original)); close #copy close #original
|
|
|
Post by Rod on Apr 22, 2018 9:19:09 GMT
I still think there is some confusion. The method that Stefan and I posted will copy ANY file no matter the size. The point I think is that a 29mb bmp is very large indeed, perhaps its actually corrupted? Its Windows limits that will be failing since Just BASIC simply uses API commands to load and save the bmp. So is the bmp really 29mb ? what dimensions does it have and can it be loaded and displayed in Just BASIC or Windows Paint?
Edit :Oh, actually Stefans solution is smarter because it simply passes the input to the output. I brought it into a variable first. So not necessary.
|
|
|
Post by Rod on Apr 22, 2018 12:12:19 GMT
I just created a 40Mb 24bit bmp, it was 4000x4000 pixels. Just BASIC copied it without problem.
loadbmp "test","test.bmp" bmpsave "test","copy.bmp" end
So not sure why you are having the failures, is there an error log or error message displayed?
Edit, no Just BASIC fails to load it, Liberty BASIC on the other hand did not have a problem.
|
|
|
Post by Rod on Apr 22, 2018 14:32:27 GMT
Ok, perhaps I'm the one confusing the situation. The code I posted above works perfectly well on Liberty BASIC v4.5.1 but not on Just BASIC v2, I get the System Primitive Failed error as soon as I hit the loadbmp command. One for Carl, the memory limits were changed for this release, perhaps that's the cause?
|
|