Author Topic: Dir Walk Challenge  (Read 6790 times)

B+

  • Guest
Dir Walk Challenge
« on: September 23, 2018, 04:03:05 PM »
Quote
Tomaaz
Full Member
***
 
Posts: 123
View Profile  Personal Message (Online)

Re: Notes on Script BASIC
« Reply #35 on: 22. September 2018, 17:48:49 »
Quote
OK. Here is another task. Recursively walk directory, find all .jpg files which names are integers, sort the names by numbers and print the result.

Ruby (one line):
Code: [Select]
puts Dir.glob("**/*").select{|a| File.extname(a) == ".jpg" and File.basename(a, ".jpg").to_i.to_s == File.basename(a, ".jpg")}.map {|a| File.basename(a, ".jpg").to_i}.sort

If you want to know what part of the code is responsible for what part of the task, I can explain it to you. It only looks cryptic. If you know basics of Ruby it's clear as
Code: [Select]
for x = 1 to 10 : print x : next x
in BASIC.  ;)

Tomaaz do you have sample screen shot of output. I am probably going to repeat a question about "map" but it might be solved by picture.

Also I assume it doesn't have to be .jpg extension or start with number maybe any base name condition is good.
I'd prefer to build something that actually might have some use for me and this sort of stuff is not but a .bas file starting with certain base names might be very useful. I mean I hate to be accused of playing around ALL of the time with my BASIC's.


@ Mike
The B of B+ mostly stands for Build as in B += .... But standing for Eternal Beginner is OK too, someone should keep the eternal flame alive.
« Last Edit: September 23, 2018, 04:11:13 PM by B+ »

Mike Lobanovsky

  • Guest
Re: Dir Walk Challenge
« Reply #1 on: September 24, 2018, 01:59:26 AM »
B+,

Actually my remark was there to cut down a little that bitter taste the whole incident left in my mouth. :)

History spins in circles, and we've seen all this before on the old BP.org. But IIRC then the instigator was that narcissistic graphomaniac that used to call himself menn, or mennonite, or bestof, or something similar. It's sad to see other people stepping into his place on this newer forum board.

Tomaaz

  • Guest
Re: Dir Walk Challenge
« Reply #2 on: September 24, 2018, 09:59:29 AM »
Tomaaz do you have sample screen shot of output. I am probably going to repeat a question about "map" but it might be solved by picture.

Output is just a bunch of numbers and it depends on what is in the directory you're running the script in.

ZXDunny

  • Guest
Re: Dir Walk Challenge
« Reply #3 on: September 24, 2018, 12:20:46 PM »
B+,

Actually my remark was there to cut down a little that bitter taste the whole incident left in my mouth. :)

History spins in circles, and we've seen all this before on the old BP.org. But IIRC then the instigator was that narcissistic graphomaniac that used to call himself menn, or mennonite, or bestof, or something similar. It's sad to see other people stepping into his place on this newer forum board.

You mean the incident where John continued slagging off other BASIC interpreter authors and calling their hobbies and efforts "toys" and worthless pursuits as opposed to his "professional" BASIC interpreter which everyone should be using (either as a template for other languages or outright as the only tool in their box)? Where I decided I'd had enough of his bitching and sniping and called him out on it? And where he flounced out of the forum - as he has done before on previous boards - in righteous indignation?

That incident?

Because god forbid that anyone gets any enjoyment out of something they create for their own pleasure, yeah?

Mike Lobanovsky

  • Guest
Re: Dir Walk Challenge
« Reply #4 on: September 24, 2018, 03:27:51 PM »
Your trying to troll me isn't going to lead you anywhere.

I said:
Quote
then the instigator was that narcissistic graphomaniac that used to call himself menn
and I said:
Quote
This is all I have to say regarding the topic, and as I have already said, I will abstain from any further fruitless discussions on it here or elsewhere.

Find yourself another target. I've seen enough of it on the old BP.org and am pretty much fed up with it since years.

ZXDunny

  • Guest
Re: Dir Walk Challenge
« Reply #5 on: September 24, 2018, 04:17:19 PM »
Oh, I'm not trolling. Even you will be able to tell when I am.

You viciously and without provocation attacked me personally, and I'm not allowed to even defend myself? I'll add that the list of things I'm not allowed to do according to some guy on the internet who goes by the name of Mike, yeah?


Tomaaz

  • Guest
Re: Dir Walk Challenge
« Reply #6 on: September 24, 2018, 06:07:36 PM »
Mike, I don't remember ZXDunny trolling anyone. He's never had problems with people using other BASICs, unlike some other members. He's never had problems with me posting code in Python, Ruby or Perl, unlike some other members. You want to see some good trolling? Sorry, you just missed one. It was here. Aurel was having laugh at OOP. It involved words like "pussy", "suck" etc., but Aurel must have gotten sober in the meantime and edited it.
« Last Edit: September 24, 2018, 06:09:48 PM by Tomaaz »

B+

  • Guest
Re: Dir Walk Challenge
« Reply #7 on: September 24, 2018, 06:53:45 PM »
Mike, I don't remember ZXDunny trolling anyone. He's never had problems with people using other BASICs, unlike some other members. He's never had problems with me posting code in Python, Ruby or Perl, unlike some other members. You want to see some good trolling? Sorry, you just missed one. It was here. Aurel was having laugh at OOP. It involved words like "pussy", "suck" etc., but Aurel must have gotten sober in the meantime and edited it.

Either that or the Moderator button works, Aurel apologized before the last edit to "0".

B+

  • Guest
Re: Dir Walk Challenge
« Reply #8 on: September 24, 2018, 07:06:52 PM »
Well I finally got a useful directory walk working from SmallBASIC.

Chris has a Keyword DIRWALK but it isn't easy for me to use but I bet Chris could extract 100 x's faster than I.

Here is code I came up with (not nearly so elegant as Ruby one liner) to extract and sort only .bas files:
Code: [Select]
'Dir Walk.bas for SmallBASIC 0.12.13 B+ 2018-09-24

CONST DEBUG = TRUE

FUNC sto(x)
  IF DEBUG THEN ? x   'debug: line record returned by DIRWALK, you should see how this monster is formatted!!!!
 
  'the extraction begins, remove brackets and split to fields
  SPLIT DISCLOSE(x, "{}"), ",", field
 
  'the name is in the 2nd field but is it a Folder name or File name?
  SPLIT field(1), ":", names
 
  'extract actual name value from names array
  name = MID(names(1), 2, LEN(names(1)) - 2)
  IF DEBUG THEN ? "Name: ";name  '<<< debug: got name right?
 
  'extract path from 6th field   
  path = DISCLOSE(RIGHTOF(field(5), ":"))
 
  'I think either "\" or "/" is being mistaken for escape code but works so... you know...
  IF MID(path, LEN(path)) = CHR(47) OR MID(path, LEN(path)) = CHR(92) THEN path = MID(path, 1, LEN(path) - 1)
  IF debug THEN ? "Path: ";path '<<<<<< debug: got path right?
 
  pathedName = path + CHR(92) + name
  IF DEBUG THEN ? "Pathed Name: ";pathedName
   
  'debug: view each return one at a time
  IF DEBUG THEN
    INPUT "OK, press enter to continue, any other + enter to quit ";wate
   
    'This doesn't always stop DIRWALK ???
    IF LEN(TRIM(wate)) THEN sto = FALSE : EXIT FUNC
    ?
  FI
 
  IF LCASE(RIGHT(pathedName, 4)) = ".bas" THEN container << pathedName
  IF x <> "" THEN sto = TRUE
END

DIRWALK "." USE sto(x)
SORT container

'check and file results
FOR i IN container DO ? i
tsave "BAS files.txt", container


Attached is a view of a debug session when everything was working to my satisfaction (good enough). You need to see the string DIRWALK returns until it's USE function returns FALSE.

Here is output file, BAS files.txt:
Code: [Select]
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer/Backup\Handy.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer/Backup\Lander update.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer/Backup\check environment variables.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer/Backup\japanese pattern.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer/Backup\window subcommands.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Ascii to multi message.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Bar Code by Galileo.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Chaos_1xt.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Eye Test #1001.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Goldwave by Johnno.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Interesting Interference Pattern.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Lander update.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\MDL test.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Mystic Memories.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Piston_Acceleration.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Screen Saver #3 Mystic Rectangles.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Shopping List.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Sierpinski circled.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Sierpinsky Flies a Kite.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\Sin table program.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\japanese pattern.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\seq test.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\text rotation fun .bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\window ask messagebox.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\window ask test.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/2018 new computer\window subcommands.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Boids\Boid watching.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Connect4/Back\Connect4 AI 1.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Connect4/Back\Connect4 start.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Connect4/Posts\Connect4 AI 1.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Connect4/Posts\Connect4 start.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Connect4\Connect4 AI 2.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Connect4\Connect4 AI 3.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Search Text\Seach text file.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Back\Make #3 Board Test Hiding.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Back\Make #4 Board Test Hiding.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Back\SB1 Sudoku Game.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Back\SB2  Sudoku Game Solver Editor.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Back\SB3  Sudoku Game Solver Editor.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Back\SB3_1  Sudoku Game Solver Editor.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Posted\Make #2 Sudoku Board.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Posted\Make #3 Board Test Hiding.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Posted\Make #4 Board Test Hiding.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Posted\Make Sudoku Board.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Posted\SB1 Sudoku Game.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Posted\SB2  Sudoku Game Solver Editor.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Posted\SB3  Sudoku Game Solver Editor.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Posted\SB3_1  Sudoku Game Solver Editor.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku/Posted\Solver - Sean Nixon.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku\SB3_2  Sudoku Game Solver Editor.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/Sudoku\quick test.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\Classic animation (Galileo).bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\Draw Shamrock.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\Draw Squeezed Heart.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\Draw heart experiment.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\Keyboard Input by Pete.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\Mandala Life revisited 2018-03-30.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\Prime compression Chris found.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\Shamrock Luck.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\Snail Problem.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\image modification.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\internet chess grabber by jsalai.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\seq test.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/clutter 2018\spiral text.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP/image 2 ascii\pixelate by chris yuck!.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\Detab Me.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\Full factor.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\Get key codes.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\Handy.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\Infinite Pong the Movie.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\L-system plant fractals.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\New bas file.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\Save As bas file.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\check environment variables.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\checkers.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\dir walk.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\eval calc.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\quick test.bas
C:\Users\marka\Desktop\SmallBasic\Small BASIIC  DESKTOP\tabs2spaces.bas


Too many I's in BASIC and the alternating slants or slashes :P

I like Tomaaz challenges, both interesting and productive for me even if they fail to be impressive.

Oh sorry Chris, I guess I didn't like pixelate? was that the cat thing? I mostly didn't like it because it didn't fit the screen, the lines were too long and printing over into next line ruining the image produced.
« Last Edit: September 24, 2018, 07:19:52 PM by B+ »

B+

  • Guest
Re: Dir Walk Challenge
« Reply #9 on: September 25, 2018, 04:09:23 PM »
You know this challenge was originally directed at Script Basic, I confess now that I worked up my boring example (probably not a great example of SmallBASIC) and Peter his, could someone offer a good representative one of Script Basic code? Maybe AlyssonR or (old) Mike?

Heck! I wouldn't mind seeing new Mike's version either! :) maybe a GUI sample, I would think it actually useful and not waste of time.

And D, can SpecBas do this?

"Inquiring minds want to know."
« Last Edit: September 25, 2018, 04:14:13 PM by B+ »

B+

  • Guest
Re: Dir Walk Challenge
« Reply #10 on: September 25, 2018, 05:06:51 PM »
see attached

Well I knew John couldn't answer my question. This is probably his real reason for leaving, this challenge.

And the attached shows the Standard response when you ask a question he can't answer about Script Basic and he is the one who wants to be surrounded by professional programmers.






jj2007

  • Guest
Re: Dir Walk Challenge
« Reply #11 on: September 26, 2018, 12:18:32 AM »
Just for fun - pure assembly, of course:
Code: [Select]
include \masm32\MasmBasic\MasmBasic.inc
  Init
  Let esi=ExpandEnv$("%WINDIR%\")+"*.*" ; usually C:\Windows
  PrintLine "Searching ", esi
  GfCallback cbGetFiles ; define a callback function
  GetFiles esi
  Print Str$("\n%i files found\n", eax) ; 2805 files found
  For_ ecx=0 To Min(19, Files$(?)) ; print a few
PrintLine Files$(ecx)
  Next
  Store "NumericalFiles.txt", Files$() ; write the complete list to disk
  Exit
cbGetFiles:
  test ecx, 1048575 ; file or folder counter
  If_ Zero? Then Print "*" ; console mode progress bar ;-)
  .if [ebx.WIN32_FIND_DATAW.dwFileAttributes]==FILE_ATTRIBUTE_DIRECTORY
clc
  .else
void Val(Utf8$(esi))
.if edx==-127
stc
.elseif edx<20
clc
.else
stc
.endif
  .endif
  ret
EndOfCode
Typical output:
Code: [Select]
Searching C:\Windows\*.*
************************************************************************************************
******************************************
2805 files found
C:\Windows\Downloaded Installations\{32641B63-651D-43D9-B6F7-8C45F2FF07E1}\1033.MST
C:\Windows\ehome\CreateDisc\Components\tables\1cb0
C:\Windows\ehome\CreateDisc\Components\tables\1cb1
C:\Windows\ehome\CreateDisc\Components\tables\1cb2
C:\Windows\ehome\CreateDisc\Components\tables\2cb0
C:\Windows\ehome\CreateDisc\Components\tables\2cb1
C:\Windows\ehome\CreateDisc\Components\tables\2cb2
C:\Windows\inf\1394.inf
C:\Windows\inf\1394.PNF
C:\Windows\inf\61883.inf
C:\Windows\inf\61883.PNF
C:\Windows\Performance\WinSAT\DataStore\0012-01-16 10.43.33.070 Cpu.Assessment (Prepop).WinSAT.xml
C:\Windows\Performance\WinSAT\DataStore\0012-01-16 10.43.33.070 Disk.Assessment (Prepop).WinSAT.xml
C:\Windows\Performance\WinSAT\DataStore\0012-01-16 10.43.33.070 DWM.Assessment (Prepop).WinSAT.xml
...
« Last Edit: September 26, 2018, 12:24:29 AM by jj2007 »

Tomaaz

  • Guest
Re: Dir Walk Challenge
« Reply #12 on: September 26, 2018, 09:45:57 AM »
To list all files, all you need in Ruby is:
Code: [Select]
puts Dir.glob("**/*")

B+

  • Guest
Re: Dir Walk Challenge
« Reply #13 on: September 26, 2018, 12:47:01 PM »
Hey JJ,

Nice to see MasmBasic in action again. Are the files coming out sorted automatically?



Hi all,

Last night I rediscovered this crucial line for QB64 processing of pathedfile lists:
Code: [Select]
SHELL _HIDE "DIR " + spec$ + " /b /s /o:gen > " + TmpFile$
Which brings back fond memories of my days with DOS.

chrisws

  • Guest
Re: Dir Walk Challenge
« Reply #14 on: September 29, 2018, 01:31:37 AM »
Well I finally got a useful directory walk working from SmallBASIC.
Chris has a Keyword DIRWALK but it isn't easy for me to use but I bet Chris could extract 100 x's faster than I.

When you launch SmallBASIC you are actually looking at the output from the DIRWALK command.

(SmallBASIC runs main.bas which provides the user interface)