Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: File attributes/status bits/protection bits

  1. #1

    File attributes/status bits/protection bits

    There are a handful of functions that depend on them, but I haven't found a way tinker with them directly. How does one go about getting or setting the flags (Hidden, Archive, Read-only, System) on a particular file?

    I acknowledge that the solution may be in plain sight and I just haven't stumbled on it yet. I do not speak (and have little desire to fully understand) Windows SDK.

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: File attributes/status bits/protection bits

    Hi harsh.

    There are no native thinBasic functions to get/set file attributes.
    But this is an idea for us so I will add them quite soon. Even if it is quite simple, we too do not like to go directly to Windows SDK, so we prefer to add a native function when asked by thinBasic users.

    I will give you back soon.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: File attributes/status bits/protection bits

    harsh,

    please find here enclosed a new thinBasic_FILE.dll module that implements 2 new functions: FILE_GetAttr, FILE_SetAttr
    To test it, place thinBasic_FILE.dll into \thinBasic\Lib\ directory replacing your current one. BE SURE TO HAVE thinBasic preview version 1.6.0.2 installed before doing that.

    Here a script example on how to use new functions:
    [code=thinbasic]
    uses "FILE"

    dim sFile as string value APP_SourceFullName & ".bak"
    '---Create a new temp file to work with copying current script file
    file_save(sFile, File_load(APP_SourceFullName))

    '---Save current attribute
    dim SaveOriginalAttr as long value file_getattr(sFile)

    msgbox 0, "File attributes for file" & $crlf & _
    sFile & $crlf & _
    "is:" & $crlf & _
    SaveOriginalAttr

    '---Change attribute to ReadOnly
    file_setattr(sFile, %FILE_READONLY)

    msgbox 0, "File attributes for file" & $crlf & _
    sFile & $crlf & _
    "is now:" & $crlf & _
    file_getattr(sFile) & $crlf(2) & _
    "Attribute will be changed back to " & SaveOriginalAttr

    '---Back to original attribute and delete it
    file_setattr(sFile, SaveOriginalAttr)
    file_kill(sFile)


    '---Legend---
    '%FILE_NORMAL 0
    '%FILE_READONLY 1
    '%FILE_HIDDEN 2
    '%FILE_SYSTEM 4
    '%FILE_VLABEL 8
    '%FILE_SUBDIR 16
    '%FILE_ARCHIVE 32
    '%FILE_NORMAL 128
    [/code]

    Functions will be present in next release.

    Regards
    Eros


    Attached file removed. Features present in thinBasic preview version 1.6.0.3
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: File attributes/status bits/protection bits

    Nice work Eros but I think it would be nice to have attributes as an option on FILE_SAVE also.

    It would save the file then set the desired attributes of that file thus saving the use of another keyword.

    What do you think?
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: File attributes/status bits/protection bits

    Abraxas,

    I was thinking about exactly the same!
    I am also all for it, as long as it is optional.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: File attributes/status bits/protection bits

    Updated attached file to previous post (did I originally attached a file ??? )

    FILE_Save has now the following syntax: [code=thinbasic]FILE_Save(File, Buffer [, Attr])[/code]

    See following example:
    [code=thinbasic]
    uses "FILE"

    dim sFile as string value APP_SourceFullName & ".bak"
    '---Create a new temp file to work with copying current script file
    file_save(sFile, File_load(APP_SourceFullName), %FILE_HIDDEN)

    '---Save current attribute
    dim SaveOriginalAttr as long value file_getattr(sFile)
    dim NewAttr as long

    msgbox 0, "File attributes for file" & $crlf & _
    sFile & $crlf & _
    "is:" & $crlf & _
    SaveOriginalAttr & "->" & AttrToStr(SaveOriginalAttr)

    '---Change attribute to ReadOnly
    file_setattr(sFile, %FILE_READONLY)

    NewAttr = file_getattr(sFile)
    msgbox 0, "File attributes for file" & $crlf & _
    sFile & $crlf & _
    "is now:" & $crlf & _
    NewAttr & _
    "->" & AttrToStr(NewAttr) & $crlf(2) & _
    "Attribute will be changed back to " & SaveOriginalAttr

    '---Back to original attribute and delete it
    file_setattr(sFile, SaveOriginalAttr)
    file_kill(sFile)


    function AttrToStr(lAttr as long) as string
    local sOut as string

    if lAttr and %FILE_NORMAL then sOut += "NORMAL "
    if lAttr and %FILE_READONLY then sOut += "READONLY "
    if lAttr and %FILE_HIDDEN then sOut += "HIDDEN "
    if lAttr and %FILE_SYSTEM then sOut += "SYSTEM "
    if lAttr and %FILE_VLABEL then sOut += "VLABEL "
    if lAttr and %FILE_SUBDIR then sOut += "SUBDIR "
    if lAttr and %FILE_ARCHIVE then sOut += "ARCHIVE "
    if lAttr and %FILE_NORMAL then sOut += "NORMAL "

    function = sOut

    end function
    [/code]

    Features will be present in next release.
    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: File attributes/status bits/protection bits

    Works good here,

    is it safe to assign to "normal" file for example %FILE_SUBDIR?


    Thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: File attributes/status bits/protection bits

    Who knows (joke)

    Well, I will limit it to just use some of them.
    The list contains possible cases.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: File attributes/status bits/protection bits

    I think it is enough to put red comment in helpfile ... only in case it is really harmful.

    I am little shy to experiment with files, because on my WinME box I accidentaly wrong-renamed one file and till the end of PC I was not able to delete it out


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  10. #10

    Re: File attributes/status bits/protection bits

    Quote Originally Posted by ErosOlmi
    please find here enclosed a new thinBasic_FILE.dll module that implements 2 new functions: FILE_GetAttr, FILE_SetAttr
    That was fast! I much appreciate your quick efforts.

Page 1 of 2 12 LastLast

Similar Threads

  1. Math with Bits
    By ErosOlmi in forum Math scripts
    Replies: 1
    Last Post: 18-03-2007, 22:41

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •