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

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
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

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • 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 »
Shuwatch!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
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

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • 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 »
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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?
Spriggsy Tree rev 2020-06-26.PNG
* Spriggsy Tree rev 2020-06-26.PNG (Filesize: 19.42 KB, Dimensions: 826x205, Views: 261)

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • 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.
output.png
* output.png (Filesize: 244.05 KB, Dimensions: 1937x1047, Views: 254)
« Last Edit: June 26, 2020, 02:37:04 pm by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • 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!
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • 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.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • 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$
eureka.png
« Last Edit: June 26, 2020, 03:45:29 pm by SpriggsySpriggs »
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • 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.
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • 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
 
alternate tree.png
 
alternate tree2.png
« Last Edit: June 26, 2020, 05:42:42 pm by SpriggsySpriggs »
Shuwatch!