open a hidden file and overwrite it ?

Hi, for security reasons I want to open a file and write "1"s to it from the begining to the end before deleting it.
I need the code please...
I also encountered this problem:
 How to delete a file that is hidden ? KILL can not do it.
Is it possible to change the file attribute without useing FSO ?
vbklausAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
You can use code like this...

  Call SetAttr("filenamehere", vbArchive)
  Kill "filenamehere"
0
VbmasterCommented:
You can write 1's to a file using code like this..

  Open "filename" For Binary As #1
  For a = 1 To Lof(1)
    Put #1, , CByte(1)
  Next
  Close #1

Of course this code can be optimized, saving a byte array with all 1's will be faster. If the file is small you can do something like this..

  Dim ByteArray() As Byte

  Open "filename" For Binary As #1
  ReDim ByteArray(Lof(1)-1)
  For a = 1 To Lof(1)
    ByteArray(a) = 1
  Next
  Put #1, , ByteArray
  Close #1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VbmasterCommented:
Dang a small error the code should be

  Dim ByteArray() As Byte

  Open "filename" For Binary As #1
  ReDim ByteArray(Lof(1)-1)
  For a = 1 To Lof(1)
    ByteArray(a-1) = 1     '<- (a-1) instead of (a) because Byte
                                     '<- Arrays starts at 0 (zero) by default
  Next
  Put #1, , ByteArray
  Close #1
0
vbklausAuthor Commented:
Thanks ! I did not know SETATTR...and the other code works fine.
0
vbklausAuthor Commented:
thanks, did I mention my array phobia ? The simple code works fast enough.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.