Author Topic: About WIN API programming  (Read 3160 times)

0 Members and 1 Guest are viewing this topic.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
About WIN API programming
« on: February 10, 2021, 10:50:53 pm »
It used to be easy in DOS to "find first file" and then "next file" in a folder

http://www.ctyme.com/intr/rb-2977.htm
http://www.ctyme.com/intr/rb-2979.htm

The API equivalent is here  https://docs.microsoft.com/en-us/windows/win32/api/fileapi/
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstfilea
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findnextfilea

but where do I get fileapi.h
This is a far as I got

Quote
To write a Windows program in C or C++, you must install the Microsoft Windows Software Development Kit (SDK) or Microsoft Visual Studio.

At least DOS had built in functions. (INT 21h etc

« Last Edit: February 10, 2021, 11:24:44 pm by NOVARSEG »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: About WIN API programming
« Reply #1 on: February 11, 2021, 02:37:52 pm »
I've always used SHELL for that.

Code: QB64: [Select]
  1. REM CAUTION: THIS ROUTINE WILL CREATE / OVERWRITE A FILE IN YOUR CURRENT FOLDER NAMED: $dir-example~tmp.tmp
  2. REM DO NOT RUN THIS ROUTINE IF FOR SOME WEIRD REASON YOU ALREADY HAVE $dir-example~tmp.tmp IN YOUR LOCAL FOLDER,...
  3. REM ... FROM SOME OTHER SOURCE OTHER THAN RUNNING THIS ROUTINE. IT WILL OVERWRITE IT!
  4.  
  5. W1% = 0 'TOP MARGIN W1% = 4-23 (MIN/MAX)
  6. W2% = 2 'LEFT MARGIN W2% = 2-78 (MIN/MAX)
  7. W3% = 22 'HEIGHT (BOTTOM MARGIN) W3% = 1-22 (MIN/MAX)
  8. W4% = 77 'LENGTH (RIGHT MARGIN) W4% = 21-77 (MIN/MAX)
  9.  
  10. LOCATE W1% + 3, W2% + 4, 0
  11. row = 1: scr = 0
  12. j = 5000: REDIM x$(j), xfull$(j)
  13. mytempfile$ = "$dir-example~tmp.tmp"
  14.  
  15. SHELL _HIDE "dir /A:-D *.txt>" + mytempfile$ ' A:-D is for only files, no directories.
  16.  
  17. ff1% = FREEFILE
  18. OPEN mytempfile$ FOR BINARY AS #ff1%
  19.  
  20. DO ' Single use falks loop.
  21.     FOR i% = 1 TO 5
  22.         IF NOT EOF(ff1%) THEN LINE INPUT #ff1%, x$ ELSE EXIT DO
  23.     NEXT
  24.  
  25.     IF EOF(ff1%) THEN EXIT DO
  26.  
  27.     DO UNTIL EOF(ff1%)
  28.         LINE INPUT #ff1%, x$
  29.         IF x$ <> mytempfile$ THEN
  30.             IF INSTR(x$, "<") = 0 AND LEFT$(x$, 1) <> " " THEN ' Excludes things like <DIR> and comments made after last file listed.
  31.                 IF LEFT$(x$, 1) = CHR$(32) THEN EXIT DO
  32.                 noe = noe + 1
  33.                 x1$ = MID$(x$, 1, 20) ' File Date
  34.                 x$ = LTRIM$(MID$(x$, 21))
  35.                 x2$ = MID$(x$, 1, INSTR(x$, CHR$(32)) - 1) ' File Size
  36.                 IF LEN(x2$) > 12 THEN x2$ = "---Large---"
  37.                 a1$ = SPACE$(12)
  38.                 MID$(a1$, 12 - LEN(x2$)) = x2$
  39.                 x2$ = a1$
  40.                 x3$ = MID$(x$, INSTR(x$, CHR$(32)) + 1) ' File Name
  41.                 a1$ = SPACE$(W4% - 31)
  42.                 MID$(a1$, 1) = MID$(x3$, 1, W4% - 31)
  43.                 a1$ = a1$ + "  " + x1$
  44.                 IF noe > 5000 THEN REDIM _PRESERVE x$(noe): REDIM _PRESERVE xfull$(noe)
  45.                 x$(noe) = a1$: xfull$(noe) = x3$
  46.             END IF
  47.         END IF
  48.     LOOP
  49.     EXIT DO
  50. CLOSE #ff1%
  51.  
  52. FOR i% = 1 TO noe
  53.     IF CSRLIN < 24 THEN
  54.         LOCATE , W2% + 4
  55.         PRINT x$(i%)
  56.     END IF

There are variations to get all directories, all directories and files, etc. Also, the /b which is the (bare) files switch, will only produce the directory and file names, without the other info. If you use that switch, the FOR NEXT loop, which discards header info, must be removed.

Zach and Mark have a few posts about using pipecom (cross platform method) to get files. Have you seen those?

Also, I may be mistaken at what you are asking here, but this is how I interpreted the post.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: About WIN API programming
« Reply #2 on: February 11, 2021, 03:11:20 pm »
@Pete
Yep! Pipecom would be great for file listings.

@NOVARSEG
If you insist on it, just search up FindFirstFile on Google. It will be one of the first results.
Shuwatch!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: About WIN API programming
« Reply #3 on: February 11, 2021, 03:27:45 pm »
What Zach said... BUT use DuckDuckGo! Google sucks. Suppressors of Free Speech.

I just did that. Ah, so you also want to find a particular file in that? That just adds a search string function, which can be made in QB64, but it all depends on the parameters of the search. The first file that starts with "c" is pretty simple. Wildcards are more difficult to code for, etc.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/