Click here to Skip to main content
Click here to Skip to main content

Tagged as

Changing File Attribute

, 22 Feb 2010
Rate this:
Please Sign up or sign in to vote.
Teaches you how to accept files and folders and change their attributes
File_Attribute

Introduction

This is a simple VB6 application that can change file or folder attributes and teach you how to accept dropped files, and files from command line. The purpose of this article is for beginners to know how to create WndProc function and translate the message WM_DROPFILES.

Accept Files

First you have to post a flag to your window that it is accept files, the easy way to use DragAcceptFiles(hWnd,fAccept). Then your window proc will reserve a message WM_DROPFILES that contains information about number of dropped files and the full path for every file.

Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long,
    ByVal lParam As Long) As Long
On Error Resume Next
        If uMsg = WM_DROPFILES Then
            On Error Resume Next
            Dim All_Number_Of_Drag_Files As Integer
            Dim Drag_File_Path           As String
            Dim Drag_File_Size           As String
            Dim Numbers                  As Long
            Dim Res                      As String
            All_Number_Of_Drag_Files = DragQueryFile(wParam, -1, vbNullString, 0)
            
            If All_Number_Of_Drag_Files = 1 Then
                Drag_File_Size = DragQueryFile(wParam, 0, vbNullString, 0)
                Drag_File_Path = Space$(255)
                DragQueryFile wParam, 0, Drag_File_Path, (Drag_File_Size + 1)
                Form1.Text1.Text = Drag_File_Path
            Else
                Form2.Show
                Form2.List1.Clear
                For Numbers = 0 To (All_Number_Of_Drag_Files - 1)
                    Drag_File_Size = DragQueryFile(wParam, Numbers, vbNullString, 0)
                    Drag_File_Path = Space$(255)
                    DragQueryFile wParam, Numbers, Drag_File_Path, (Drag_File_Size + 1)
                    If Do_File(True, Drag_File_Path) = True Then Res = 
                        "True : " Else: Res = "False: "
                    Form2.List1.AddItem (Res & Drag_File_Path)
                Next
            End If
        End If
    WindowProc = CallWindowProc(PrevProc, hWnd, uMsg, wParam, lParam)
End Function

Changing File Attributes

The file attributes is:

  • ReadOnly: This flag means that applications can't edit or delete the file or folder.
  • Hidden: This flag means that the file is invisible to you and windows explorer will discard it.
  • Archive: This flag means that the file is archived in the hard disk.
  • SystemFile: This flag means that the file is a system file and it's important.

I've used File System Object here to edit the file attributes, you can use API's instead like this:

Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_SYSTEM = &H4
Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
Public Const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = &H2000
Public Const FILE_ATTRIBUTE_OFFLINE = &H1000
Public Declare Function SetFileAttributes Lib "kernel32" Alias _
"SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
Public Function SetAttr(ByVal lpFile As String, ByVal Flags As Long) As Boolean
    SetAttr = SetFileAttributes(lpFile, Flags)
End Function 

You can learn more about file attributes by reading this.

Finally, I would like to thank you for reading my article.

History

  • 22nd February, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

My name is Hosam Hasan Ershedat and I'm studying computer Engineering now in Jordan University For Since And Technology

Comments and Discussions

 
QuestionI want to set ntfs security to any file and folder using vb6,VBScript,VB.NET PinmemberVishal I. Sahuji6-Jan-13 2:56 
How to set ntfs security to any file using vb6,VBScript,VB.NET.
GeneralMy vote of 2 PinmemberAxelM22-Feb-10 20:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 22 Feb 2010
Article Copyright 2010 by Hosam Ershedat
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid