Solved

How do I read a file's Properties

Posted on 1999-01-06
5
200 Views
Last Modified: 2008-03-06
What I need to do is look at all of the files (Excell, PowerPoint...) in a certain location, compare their properties (name, size, date created) with the files I already have, and, if I don't have that file already, copy the file to a new location.

I need to know how to read the files properties, and also how to copy the file to another location.
0
Comment
Question by:carla1
  • 2
  • 2
5 Comments
 

Author Comment

by:carla1
Comment Utility
Edited text of question
0
 
LVL 2

Expert Comment

by:trillo
Comment Utility
You can use API's.
You can retrieve the Files properties using "GetFileAttributes" function.
If the function succeeds, the return value contains the attributes of the specified file or directory.
If the function fails, the return value is 0xFFFFFFFF. To get extended error information, call GetLastError.
The attributes can be one or more of the following values:
FILE_ATTRIBUTE_ARCHIVE      The file or directory is an archive file or directory. Applications use this flag to mark files for backup or removal.
FILE_ATTRIBUTE_COMPRESSED      The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories.
FILE_ATTRIBUTE_DIRECTORY      The "file or directory" is a directory.
FILE_ATTRIBUTE_HIDDEN      The file or directory is hidden. It is not included in an ordinary directory listing.
FILE_ATTRIBUTE_NORMAL      The file or directory has no other attributes set. This attribute is valid only if used alone.
FILE_ATTRIBUTE_OFFLINE      The data of the file is not immediately available. Indicates that the file data has been physically moved to offline storage.
FILE_ATTRIBUTE_READONLY      The file or directory is read-only. Applications can read the file but cannot write to it or delete it. In the case of a directory, applications cannot delete it.
FILE_ATTRIBUTE_SYSTEM      The file or directory is part of, or is used exclusively by, the operating system.
FILE_ATTRIBUTE_TEMPORARY      The file is being used for temporary storage. File systems attempt to keep all of the data in memory for quicker access rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.

You can retrieve the file Date using "GetFileTime", the size with "GetFileSize", an you can retrieve a lot of information on a file using "GetFileInformationByHandle" which needs a "BY_HANDLE_FILE_INFORMATION" structure... Although these functions need a handle to an open file, which you can obtain with "CreateFile"...

All the declarations needed can be found in your API text viewer.
If you have any questions, just tell me.
0
 

Expert Comment

by:jmnolan
Comment Utility
APIs would work, but you really want to do something more like this.

To copy a file, use the FileCopy command like this

FileCopy SourcePath, DestinationPath

Here is how you would go through a directory and get the file attrbiutes you want:

Dim Attr1 As String
Dim Attr2 As Long
Dim MyPath, MyName

MyPath = "c:\*.*"  ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.

Do While MyName <> ""   ' Start the loop.
    'Ignore the current directory and the encompassing directory.
    If MyName <> "." And MyName <> ".." Then
        Attr1 = FileDateTime("c:\" & MyName)
        Attr2 = FileLen("c:\" & MyName)
        MsgBox "c:\" & MyName & vbCrLf & Attr1 & vbCrLf & Attr2
    End If
    MyName = Dir    ' Get next entry.
Loop


0
 

Author Comment

by:carla1
Comment Utility
Your answer was helpful, but jmnolan's answer was what I was looking for.

jmnolan: Your code worked great.  If you want the points, please post your answer for me to accept.
Thanks
0
 

Accepted Solution

by:
jmnolan earned 50 total points
Comment Utility
Please refer to my comment.. =)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now