Author Topic: DIR$ function is missing  (Read 3011 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: DIR$ function is missing
« Reply #15 on: October 26, 2020, 09:07:01 pm »
@SpriggsySpriggs Looking at best answer it's no different than

DIM F AS STRING
CHDIR "c:\qb64\my programs"

shell "dir /b *.bas | clip"
f=_clipboard$

PRINT F

But which way would be faster (by code execution time) ?  Which one could hold more data ? (me thinks windows clipboard)
@doppler
You say it is not different but it actually is quite different. I'm reading in a buffer of data and returning the buffer. Your way shows saving data to the clipboard and reading it. That would be annoying for people who use the clipboard and have things saved to it. If they aren't using the new Clipboard History feature of Windows 10 then you are just having them overwrite the last thing they copied. And as for holding data, you are holding quite literally the same amount of data whether you use my way or your way. Also, my way is faster as you can see from the screenshot. Your way slows down because you are "piping" to clip making the command prompt have to do more things.

My test code:
Code: QB64: [Select]
  1. DECLARE LIBRARY "pipecom"
  2.     FUNCTION pipecom$ (cmd AS STRING)
  3.  
  4. x# = TIMER(0.01)
  5. F = pipecom("dir /b *.BAS")
  6.  
  7. y# = TIMER(0.01)
  8. PRINT "Pipecom:", y# - x#
  9.  
  10. x# = TIMER(0.01)
  11. SHELL "dir /b *.BAS | clip"
  12.  
  13. y# = TIMER(0.01)
  14. PRINT "Doppler:", y# - x#

  [ You are not allowed to view this attachment ]  
« Last Edit: October 26, 2020, 09:09:14 pm by SpriggsySpriggs »
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: DIR$ function is missing
« Reply #16 on: October 26, 2020, 10:22:29 pm »
@SpriggsySpriggs Looking at best answer it's no different than

DIM F AS STRING
CHDIR "c:\qb64\my programs"

shell "dir /b *.bas | clip"
f=_clipboard$

PRINT F

But which way would be faster (by code execution time) ?  Which one could hold more data ? (me thinks windows clipboard)

But can you get Clipboard contents after a shell? But I hadn't tried through Windows clip that would be cool. I've tried through QB64 clipboard and no luck, maybe my slants were backwards ;-))

Nope:
Code: QB64: [Select]
  1. SHELL "dir /b *.BAS | clip"
  2.  
  3.  

Crap I forgot this runs files in QB64 directory until saved, it did work! I didn't recognize the contents ;-))
« Last Edit: October 26, 2020, 10:29:03 pm by bplus »

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: DIR$ function is missing
« Reply #17 on: October 27, 2020, 06:58:40 pm »
@SpriggsySpriggs
I suspected the shell way would be slower.  If you don't mind destroying the clipboard the data objective is the same. I may just play again with some working code to use your pipe.h  I need to use the cmd /c with windows string search findstr.  I decided against F.A.R.T. ing it.  I will us FART on other stuff.  I have a large filename dataset to search against an even larger text file of filenames.  And I have to check for variations of names.  That's an awful lot of (for i,j,k ... next k,j,i ) loops.  I will take the speed up pipe could give.

My toybox is becoming very full.  I need to get a bigger one.

@bplus Just remember clipboard will be zero on failed content and be delimited by cr/lf's  Using the clipboard to push around same chunks of data is the way Microsoft suggests to be used in .net.  I guess the big stuff should go thru DCOM interface.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: DIR$ function is missing
« Reply #18 on: October 27, 2020, 07:05:28 pm »
@doppler  man! this is so simple for 2-3 years I've been looking for something half this good then Spriggsy shows a real break through and then you show a better! You guys get my nomination for Tip of the Month!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: DIR$ function is missing
« Reply #19 on: October 27, 2020, 07:57:22 pm »
@doppler  man! this is so simple for 2-3 years I've been looking for something half this good then Spriggsy shows a real break through and then you show a better! You guys get my nomination for Tip of the Month!
@bplus My main complaint against using "clip" is that in doing so you are possibly showing the user how your code works which is not always something you want to do. You really want your functions to be hidden because if they just start seeing console output in their clipboard then the magic is lost. Also, like I was telling doppler, you don't want to overwrite the clipboard as many people don't have Windows 10 and those who do haven't enabled Clipboard History so you would be overwriting something they might want on the clipboard. If you are going to overwrite their clipboard it might be wise to tell them first or read the clipboard into a string, do your thing, then copy it back to the clipboard.
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: DIR$ function is missing
« Reply #20 on: October 27, 2020, 08:04:40 pm »
@SpriggsySpriggs Well I think we can save the contents get the info and then replace the contents if that is your concern.

I am not sure how the user is going to see the SHELL, I think there is HIDE option but so what if user sees?

Say does Linux have | clip option?





« Last Edit: October 27, 2020, 08:06:03 pm by bplus »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: DIR$ function is missing
« Reply #21 on: October 27, 2020, 08:25:46 pm »
@bplus I wasn't saying seeing the SHELL; I was talking about seeing the console output in their clipboard when they go to paste something they might have copied prior the program being ran. Linux does have a similar command but it doesn't come pre-installed. Here is some info concerning that. https://opensource.com/article/19/7/xclip

By the way, remember my recursive directory search using PowerShell? Yeah, it doesn't work piping it to clip. It does, however, work fine in pipecom. In 33 seconds I obtained the ENTIRE recursive listing of EVERY SINGLE FILE in EVERY SINGLE FOLDER in Program Files (x86) which resulted in a string of 24,655,989 bytes. According to Google, the maximum you can store in a Windows 10 clipboard for one item is 4 megabytes, or 4,000,000 bytes which is why piping to clip does not work with my command.

Code: QB64: [Select]
  1.  
  2. DECLARE LIBRARY "pipecom"
  3.     FUNCTION pipecom$ (cmd AS STRING)
  4.  
  5.  
  6. x# = TIMER(0.01)
  7. Path$ = "C:\Program Files (x86)" '\Steam\steamapps\common"
  8. comm = pipecom("PowerShell Get-ChildItem -Path \" + CHR$(34) + Path$ + "\" + CHR$(34) + " -Recurse -Force -ErrorAction SilentlyContinue -Attributes Hidden, !Hidden ^| Select-Object -ExpandProperty FullName ^| Sort-Object ^| Format-Table -AutoSize")
  9.  
  10. y# = TIMER(0.01)
  11. PRINT comm, LEN(comm)
  12. PRINT y# - x#; " seconds"
« Last Edit: October 27, 2020, 08:35:10 pm by SpriggsySpriggs »
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: DIR$ function is missing
« Reply #22 on: October 27, 2020, 09:01:57 pm »
OK all better!

Code: QB64: [Select]
  1. save$ = _CLIPBOARD$
  2. SHELL "dir /b *.BAS | clip" ' < Please note clipboard holds only a max 4,000,000+ bytes so stay out of Windows folders ;-))
  3. PRINT _CLIPBOARD$ ' or save the string to split later and process
  4. _CLIPBOARD$ = save$
  5.  
  6. '!!!!!!!!!!!!!!!!! comment out the code below that was test paste from clipboard before testing above code
  7.  
  8. 'copied this to clipboard before test run of code above then pasted here after run ========================================
  9. save$ = _CLIPBOARD$
  10. SHELL "dir /b *.BAS | clip" ' < Please note clipboard holds only a max 4,000,000+ bytes so stay out of Windows folders ;-))
  11. PRINT _CLIPBOARD$ ' or save the string to split later and process
  12. _CLIPBOARD$ = save$
  13. '================================================================ looks good!
  14.  
  15.  

;-))