?
Solved

How do I read a file's Properties

Posted on 1999-01-06
5
Medium Priority
?
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:carla1
ID: 1454404
Edited text of question
0
 
LVL 2

Expert Comment

by:trillo
ID: 1454405
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
ID: 1454406
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
ID: 1454407
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 200 total points
ID: 1454408
Please refer to my comment.. =)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 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