Author Topic: Is it possible to create a file with hidden attribute set?  (Read 2023 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Is it possible to create a file with hidden attribute set?
« on: April 08, 2020, 11:45:58 pm »
I have a program that creates a lot of temporary files to store the output of command line programs run via a SHELL command. If the user runs the program from their desktop, this results in a lot of temporary files getting created on the desktop.

Is there any way to create a file as hidden right at the time of creation? I know that I could shell an "ATRRIB" command after creation, but I'm just wondering if there is any way to create the file so that it is hidden immediately at the time of creation.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is it possible to create a file with hidden attribute set?
« Reply #1 on: April 08, 2020, 11:50:17 pm »
Why note just create the files in your temp directory; that's what it's there for?  Usually it's C:/TEMP or C:/TMP, though that's not 100% guaranteed.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Marked as best answer by hanness on April 11, 2020, 09:07:06 pm

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Is it possible to create a file with hidden attribute set?
« Reply #2 on: April 09, 2020, 01:02:02 am »
For windows Vista and later it's located at:

%USERPROFILE%\AppData\Local\Temp

You can also create the files and then shell this command to hide them:

ATTRIB +H filename.ext

The to unhide them for deleting later on:

ATTRIB -H filename.ext

If you give all your files that you want to hide the same extension, such as .TMP then you can:

ATTRIB +H *.tmp
In order to understand recursion, one must first understand recursion.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Is it possible to create a file with hidden attribute set?
« Reply #3 on: April 09, 2020, 03:39:49 am »
No. There is no direct way in QB64 to create file attributes upon save.

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

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Is it possible to create a file with hidden attribute set?
« Reply #4 on: April 09, 2020, 08:58:47 am »
Under windows you could use kernel32 to get/set file attributes.  Here's some code I had for a QB64 file manager I never finished.  It seemed to work OK, what little I have tried it.

- Dav

Code: QB64: [Select]
  1. '==============
  2. 'API-ATTRIB.BAS
  3. '==============
  4. 'Get/Set File Attribues using kernel32 functions.
  5. 'THIS IS FOR QB64 IN WINDOWS ONLY!
  6. 'Coded by Dav, APR/2020
  7.  
  8.     'If GetFileAttibutesA fails it returns -1
  9.     'More info: http://allapi.mentalis.org/apilist/GetFileAttributes.shtml
  10.     FUNCTION GetFileAttributesA& (lpFileName$)
  11.     'If SetFileAttributesA fails it returns 0
  12.     'More info: http://allapi.mentalis.org/apilist/SetFileAttributes.shtml
  13.     FUNCTION SetFileAttributesA& (lpFileName$, BYVAL dwFileAttributes AS LONG)
  14.     'You can use getLastError to get extended error information
  15.     FUNCTION GetLastError& ()
  16.  
  17. CONST FILE_ATTRIBUTE_READONLY = 1
  18. CONST FILE_ATTRIBUTE_HIDDEN = 2
  19. CONST FILE_ATTRIBUTE_SYSTEM = 4
  20. CONST FILE_ATTRIBUTE_DIRECTORY = 16
  21. CONST FILE_ATTRIBUTE_ARCHIVE = 32
  22. CONST FILE_ATTRIBUTE_NORMAL = 128
  23. CONST FILE_ATTRIBUTE_TEMPORARY = 256
  24. CONST FILE_ATTRIBUTE_COMPRESSED = 2048
  25.  
  26.  
  27. 'Filename must be null terminated.
  28. 'Take a look at qb64.exe file...
  29.  
  30. PRINT GetFileAttributesA("qb64.exe" + CHR$(0))
  31.  
  32. 'It should show 32, which means ARCHIVE attribute
  33.  
  34.  

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Is it possible to create a file with hidden attribute set?
« Reply #5 on: April 12, 2020, 12:35:23 am »
Thanks for the suggestions. It was more just a question out of curiosity to know if it was possible.