Author Topic: Development of a program for automatic search for music and movies  (Read 1597 times)

Offline Petr

  • Forum Resident
  • Posts: 1354
  • The best code is the DNA of the hops.
Re: Development of a program for automatic search for music and movies
« Reply #30 on: June 26, 2020, 12:31:17 PM »
I'm very pleased. I am very pleased with your help. I'm completely lost in mine code. I have to say that you know recursion much better than I can. Now I'm trying to figure out why subdirectories are missing in the list of folders in the last two directories. In any case, your programs are much clearer than mine.

I didn't realize one thing. That I have written the full path in array. So I'm not going to go back one directory level, so I don't need to write down the current nesting level. Now, looking at the BPlus and Steve code, I've figured it out. It just occurred to me now. I did it absolutely wrong.

I think, maybe... see to BPlus source. To MakeTree SUB. If is this SUB recursive running, then source list of arrays is deleted in next step (in recursive call), or not?

Offline bplus

  • Forum Resident
  • Posts: 4616
  • B+ nots
Re: Development of a program for automatic search for music and movies
« Reply #31 on: June 26, 2020, 12:44:03 PM »
I just tried modified version of @SpriggsySpriggs, very nice!

According to his version, we are shooting for 607 sub-dirs, so 125 is definitely falling short.

Offline bplus

  • Forum Resident
  • Posts: 4616
  • B+ nots
Re: Development of a program for automatic search for music and movies
« Reply #32 on: June 26, 2020, 12:54:49 PM »
@Petr

Glad to have cleared the "big head", working on your code did inspire me to try the recursive tree making.

Quote
I think, maybe... see to BPlus source. To MakeTree SUB. If is this SUB recursive running, then source list of arrays is deleted in next step (in recursive call), or not?

In recursive call (when setup properly), every new call to sub makes it's own set of variables including arrays, be careful with the calling parameters sometimes making a copy of them helps in case they get altered by code. Hey... is that what I missed?

The calls go down and down and down until no more down, then up one level and finish laterally, then up next level and finish that. I learned this by watching recursive drawings.


Offline SpriggsySpriggs

  • Seasoned Forum Regular
  • Posts: 271
  • DIM JohnSilver AS LONG, yarn AS STRING
    • My GitHub
Re: Development of a program for automatic search for music and movies
« Reply #33 on: June 26, 2020, 01:22:14 PM »
I just tried modified version of @SpriggsySpriggs, very nice!
According to his version, we are shooting for 607 sub-dirs, so 125 is definitely falling short.
@bplus Perhaps not, actually. That version might have been bugged. Try this one:
Code: QB64: [Select]
  1. Path$ = _STARTDIR$
  2. SHELL _HIDE "PowerShell Get-ChildItem -Path \" + CHR$(34) + Path$ + "\" + CHR$(34) + " -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName | Format-Table -AutoSize | Out-File -FilePath directorylist.txt -Encoding ASCII"
  3. DIRECTORIES = FREEFILE
  4. n = 0
  5.  
  6. DIM Dirs(n) AS STRING
  7. OPEN "directorylist.txt" FOR BINARY AS #DIRECTORIES
  8.     LINE INPUT #DIRECTORIES, Directory$
  9.     Directory$ = LTRIM$(RTRIM$(STRING.Remove(Directory$, CHR$(13))))
  10.     n = n + 1
  11.     REDIM _PRESERVE Dirs(n)
  12.     Dirs(n) = Directory$
  13. LOOP UNTIL EOF(DIRECTORIES)
  14.  
  15. FOR i = 1 TO UBOUND(Dirs)
  16.     IF LEFT$(Dirs(i), _INSTRREV(Dirs(i), "\") - 1) <> LEFT$(Dirs(i - 1), _INSTRREV(Dirs(i - 1), "\") - 1) THEN
  17.         h = h + 1
  18.         a = Array_String.FirstOrDefault(Dirs(), LEFT$(Dirs(i), _INSTRREV(Dirs(i), "\") - 1), 1)
  19.         PRINT h, Dirs(a)
  20.     END IF
  21.  
  22.  
  23. FUNCTION STRING.Remove$ (a AS STRING, b AS STRING)
  24.     DIM c AS STRING
  25.     c = ""
  26.     j = INSTR(a, b)
  27.     IF j > 0 THEN
  28.         r$ = LEFT$(a, j - 1) + c + STRING.Remove(RIGHT$(a, LEN(a) - j + 1 - LEN(b)), b)
  29.     ELSE
  30.         r$ = a
  31.     END IF
  32.     STRING.Remove = r$
  33.  
  34. FUNCTION Array_String.FirstOrDefault (SearchArray() AS STRING, SearchString AS STRING, contains AS INTEGER)
  35.     FOR i = LBOUND(SearchArray) TO UBOUND(SearchArray)
  36.         IF contains = 1 THEN
  37.             IF INSTR(SearchArray(i), SearchString) THEN
  38.                 Array_String.FirstOrDefault = i
  39.                 EXIT FUNCTION
  40.             END IF
  41.         ELSEIF contains = 0 THEN
  42.             IF SearchArray(i) = SearchString THEN
  43.                 Array_String.FirstOrDefault = i
  44.                 EXIT FUNCTION
  45.             END IF
  46.         END IF
  47.     NEXT
« Last Edit: June 26, 2020, 01:24:12 PM by SpriggsySpriggs »

Offline Petr

  • Forum Resident
  • Posts: 1354
  • The best code is the DNA of the hops.
Re: Development of a program for automatic search for music and movies
« Reply #34 on: June 26, 2020, 01:29:18 PM »
Hi SpriggsySpriggs, your program create empty file directorylist.txt here.

Which PowerShell version is need? I use Win 7.
« Last Edit: June 26, 2020, 01:31:47 PM by Petr »

Offline SpriggsySpriggs

  • Seasoned Forum Regular
  • Posts: 271
  • DIM JohnSilver AS LONG, yarn AS STRING
    • My GitHub
Re: Development of a program for automatic search for music and movies
« Reply #35 on: June 26, 2020, 01:31:39 PM »
Hi SpriggsySpriggs, your program create empty file directorylist.txt here.
That would probably be because your PowerShell failed and didn't create a file. Don't end the Path$ with a backslash. The backslash is an escape character to escape the quotes in the SHELL string and pass the quoted path. If you add a backslash it fails unless you add two.
« Last Edit: June 26, 2020, 01:37:53 PM by SpriggsySpriggs »

Offline bplus

  • Forum Resident
  • Posts: 4616
  • B+ nots
Re: Development of a program for automatic search for music and movies
« Reply #36 on: June 26, 2020, 02:24:04 PM »
@bplus Perhaps not, actually. That version might have been bugged. Try this one:
Code: QB64: [Select]
  1. Path$ = _STARTDIR$
  2. SHELL _HIDE "PowerShell Get-ChildItem -Path \" + CHR$(34) + Path$ + "\" + CHR$(34) + " -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName | Format-Table -AutoSize | Out-File -FilePath directorylist.txt -Encoding ASCII"
  3. DIRECTORIES = FREEFILE
  4. n = 0
  5.  
  6. DIM Dirs(n) AS STRING
  7. OPEN "directorylist.txt" FOR BINARY AS #DIRECTORIES
  8.     LINE INPUT #DIRECTORIES, Directory$
  9.     Directory$ = LTRIM$(RTRIM$(STRING.Remove(Directory$, CHR$(13))))
  10.     n = n + 1
  11.     REDIM _PRESERVE Dirs(n)
  12.     Dirs(n) = Directory$
  13. LOOP UNTIL EOF(DIRECTORIES)
  14.  
  15. FOR i = 1 TO UBOUND(Dirs)
  16.     IF LEFT$(Dirs(i), _INSTRREV(Dirs(i), "\") - 1) <> LEFT$(Dirs(i - 1), _INSTRREV(Dirs(i - 1), "\") - 1) THEN
  17.         h = h + 1
  18.         a = Array_String.FirstOrDefault(Dirs(), LEFT$(Dirs(i), _INSTRREV(Dirs(i), "\") - 1), 1)
  19.         PRINT h, Dirs(a)
  20.     END IF
  21.  
  22.  
  23. FUNCTION STRING.Remove$ (a AS STRING, b AS STRING)
  24.     DIM c AS STRING
  25.     c = ""
  26.     j = INSTR(a, b)
  27.     IF j > 0 THEN
  28.         r$ = LEFT$(a, j - 1) + c + STRING.Remove(RIGHT$(a, LEN(a) - j + 1 - LEN(b)), b)
  29.     ELSE
  30.         r$ = a
  31.     END IF
  32.     STRING.Remove = r$
  33.  
  34. FUNCTION Array_String.FirstOrDefault (SearchArray() AS STRING, SearchString AS STRING, contains AS INTEGER)
  35.     FOR i = LBOUND(SearchArray) TO UBOUND(SearchArray)
  36.         IF contains = 1 THEN
  37.             IF INSTR(SearchArray(i), SearchString) THEN
  38.                 Array_String.FirstOrDefault = i
  39.                 EXIT FUNCTION
  40.             END IF
  41.         ELSEIF contains = 0 THEN
  42.             IF SearchArray(i) = SearchString THEN
  43.                 Array_String.FirstOrDefault = i
  44.                 EXIT FUNCTION
  45.             END IF
  46.         END IF
  47.     NEXT

This has obvious errors from get go InForm files. What did you think was buggy from first version?

Offline SpriggsySpriggs

  • Seasoned Forum Regular
  • Posts: 271
  • DIM JohnSilver AS LONG, yarn AS STRING
    • My GitHub
Re: Development of a program for automatic search for music and movies
« Reply #37 on: June 26, 2020, 02:30:42 PM »
Well I was getting
This has obvious errors from get go InForm files. What did you think was buggy from first version?
I don't get two InForm folders when I run it. Did you change any of the logic unintentionally? From my first version I would get around 700 directories. This version gets around 200 on mine right now. That seems to be more consistent with what you and Petr found.
Oh crap, I think I see something wrong. Maybe permissions? Apologies, let me investigate further.
« Last Edit: June 26, 2020, 02:37:04 PM by SpriggsySpriggs »

Offline SpriggsySpriggs

  • Seasoned Forum Regular
  • Posts: 271
  • DIM JohnSilver AS LONG, yarn AS STRING
    • My GitHub
Re: Development of a program for automatic search for music and movies
« Reply #38 on: June 26, 2020, 02:37:57 PM »
Shoot, yeah there is something wrong. 700 folders actually is correct for what I should have on my PC. My logic is wrong in the loop. I'll post a different version later. So sorry!

Offline bplus

  • Forum Resident
  • Posts: 4616
  • B+ nots
Re: Development of a program for automatic search for music and movies
« Reply #39 on: June 26, 2020, 02:42:12 PM »
@SpriggsySpriggs

I ran your 2nd version from a straight copy/paste from forum. It is possible the forum editor changed something.

BTW what determines the Console Width, man Spriggsy, yours looks to have acre's of room!

Don't go by my Tree, I was getting (125 sub-dirs), kind of fails to get more sub-Folders after License (that has no sub-dirs).

Time for an independent evaluation of QB64 folder, I am thinking your first was right. ;-) too!
« Last Edit: June 26, 2020, 02:43:26 PM by bplus »

Offline SpriggsySpriggs

  • Seasoned Forum Regular
  • Posts: 271
  • DIM JohnSilver AS LONG, yarn AS STRING
    • My GitHub
Re: Development of a program for automatic search for music and movies
« Reply #40 on: June 26, 2020, 02:44:46 PM »
@SpriggsySpriggs

I ran your 2nd version from a straight copy/paste from forum. It is possible the forum editor changed something.

BTW what determines the Console Width, man Spriggsy, yours looks to have acre's of room!

Don't go by my Tree, I was getting (125 sub-dirs), kind of fails to get more sub-Folders after License (that has no sub-dirs).

Time for an independent evaluation of QB64 folder, I am thinking your first was right. ;-) too!
The first one was literally just reading in the file and then printing the results. It doesn't quite follow the tree structure, though. I'm going to have to see about how to make PowerShell organize it as such or how to sort the array (argh). So yeah, more work :( Thank you for catching that issue.

Offline SpriggsySpriggs

  • Seasoned Forum Regular
  • Posts: 271
  • DIM JohnSilver AS LONG, yarn AS STRING
    • My GitHub
Re: Development of a program for automatic search for music and movies
« Reply #41 on: June 26, 2020, 03:43:19 PM »
@SpriggsySpriggs
I ran your 2nd version from a straight copy/paste from forum. It is possible the forum editor changed something.
@bplus It wasn't your fault at all. I neglected to sort the items. They were there all along! I sorted them using the SHELL with Sort-Object and now they are in the correct recursive order and with the 700~ directories. Check it out:
Code: QB64: [Select]
  1. Path$ = _STARTDIR$
  2. SHELL _HIDE "PowerShell Get-ChildItem -Path \" + CHR$(34) + Path$ + "\" + CHR$(34) + " -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName | Sort-Object | Format-Table -AutoSize | Out-File -FilePath directorylist.txt -Encoding ASCII"
  3. DIRECTORIES = FREEFILE
  4. n = 0
  5.  
  6. DIM Dirs(n) AS STRING
  7. OPEN "directorylist.txt" FOR BINARY AS #DIRECTORIES
  8.     LINE INPUT #DIRECTORIES, Directory$
  9.     Directory$ = LTRIM$(RTRIM$(STRING.Remove(Directory$, CHR$(13))))
  10.     n = n + 1
  11.     REDIM _PRESERVE Dirs(n)
  12.     Dirs(n) = Directory$
  13. LOOP UNTIL EOF(DIRECTORIES)
  14. CLOSE #DIRECTORIES
  15. FOR i = 1 TO UBOUND(Dirs)
  16.     PRINT i, Dirs(i)
  17.  
  18.  
  19. FUNCTION STRING.Remove$ (a AS STRING, b AS STRING)
  20.     DIM c AS STRING
  21.     c = ""
  22.     j = INSTR(a, b)
  23.     IF j > 0 THEN
  24.         r$ = LEFT$(a, j - 1) + c + STRING.Remove(RIGHT$(a, LEN(a) - j + 1 - LEN(b)), b)
  25.     ELSE
  26.         r$ = a
  27.     END IF
  28.     STRING.Remove = r$
« Last Edit: June 26, 2020, 03:45:29 PM by SpriggsySpriggs »

Offline SpriggsySpriggs

  • Seasoned Forum Regular
  • Posts: 271
  • DIM JohnSilver AS LONG, yarn AS STRING
    • My GitHub
Re: Development of a program for automatic search for music and movies
« Reply #42 on: June 26, 2020, 03:48:06 PM »
@SpriggsySpriggs
BTW what determines the Console Width, man Spriggsy, yours looks to have acre's of room!
I just maximized the console window. I'm on a 24 inch monitor so I guess that's why I have so much space.

Offline bplus

  • Forum Resident
  • Posts: 4616
  • B+ nots
Re: Development of a program for automatic search for music and movies
« Reply #43 on: June 26, 2020, 04:11:17 PM »
Ah maximize window, yeah that helps, only one Directory doesn't fit on line then for me.

I get 607 folders. I don't think I've added any folders to QB64 folder, plenty of files but no folders. What is the difference I wonder. Update: oh I thought it was 700+ the first time, no, same as first 607. OK consistency is good!

I've been messing with my recursive thing, got the recursive up to 267 files was it? but forgot what I did.
Man I am making little changes to variables and getting differences in counts, but nothing like 600 listings.

Oh! I might be loosing folders with decimal points!
« Last Edit: June 26, 2020, 04:21:06 PM by bplus »

Offline SpriggsySpriggs

  • Seasoned Forum Regular
  • Posts: 271
  • DIM JohnSilver AS LONG, yarn AS STRING
    • My GitHub
Re: Development of a program for automatic search for music and movies
« Reply #44 on: June 26, 2020, 05:35:32 PM »
Or, alternatively, this:
Code: QB64: [Select]
  1.  
  2. Path$ = "C:\Program Files (x86)\Steam\steamapps\common"
  3. SHELL _HIDE "PowerShell Tree \" + CHR$(34) + Path$ + "\" + CHR$(34) + " /a | Select-Object -Skip 2 | Set-Content tree.txt"
  4. tree = FREEFILE
  5. OPEN "tree.txt" FOR BINARY AS #tree
  6.     LINE INPUT #tree, branch$
  7.     PRINT branch$
  8. LOOP UNTIL EOF(tree)
  9. CLOSE #tree
  10. FUNCTION STRING.Remove$ (a AS STRING, b AS STRING)
  11.     DIM c AS STRING
  12.     c = ""
  13.     j = INSTR(a, b)
  14.     IF j > 0 THEN
  15.         r$ = LEFT$(a, j - 1) + c + STRING.Remove(RIGHT$(a, LEN(a) - j + 1 - LEN(b)), b)
  16.     ELSE
  17.         r$ = a
  18.     END IF
  19.     STRING.Remove = r$
PowerShell has a built in function for displaying folders and files in a tree format
 
 
« Last Edit: June 26, 2020, 05:42:42 PM by SpriggsySpriggs »