Program for extracting file attributes written by Windows API

Source: Internet
Author: User
The Win32 console application is created in the compiling environment of VC ++ 6.0.

# Include <stdafx. h>
# Include <string. h>
# Include <windows. h>

DWORD showfiletime (pfiletime lptime)
{
// File Time Structure
Filetime ftlocal;
// System Time Structure
Systemtime st;
// Adjust the time to the system's Time Zone
Filetimetolocalfiletime (lptime, & ftlocal );
// Convert the file time to the systemtime format for easy display
Filetimetosystemtime (& ftlocal, & St );
// Display the time string
Printf ("% 4D year % # 02d month % # 02d day, % # 02d: % # 02d: % # 02d \ n", St. wyear, St. wmonth, St. wday, St. whour, St. wminute, St. wsecond );
Return 0;
}

DWORD showfilesize (DWORD dwfilesizehigh, DWORD dwfilesizelow)
{
Ulonglong lifilesize;
Lifilesize = dwfilesizehigh;
// Move to 32 bits
Lifilesize <= sizeof (DWORD) * 8;
Lifilesize + = dwfilesizelow;
Printf ("W file size: \ t % i64u byte \ n", lifilesize );
Return 0;
}

DWORD showfileattrinfo (DWORD dwattribute)
{
// Judge and display attributes in sequence
Printf ("file attributes: \ t ");
If (dwattribute & file_attribute_archive)
Printf ("<archive> ");
If (dwattribute & file_attribute_compressed)
Printf ("<compression> ");
If (dwattribute & file_attribute_directory)
Printf ("<directory> ");
If (dwattribute & file_attribute_encrypted)
Printf ("<encryption> ");
If (dwattribute & file_attribute_hidden)
Printf ("If (dwattribute & file_attribute_normal)
Printf ("<normal> ");
If (dwattribute & file_attribute_offline)
Printf ("<offline> ");
If (dwattribute & file_attribute_readonly)
Printf ("<read-only> ");
If (dwattribute & file_attribute_sparse_file)
Printf ("<sparse> ");
If (dwattribute & file_attribute_system)
Printf ("<System File> ");
If (dwattribute & file_attribute_temporary)
Printf ("<Temporary File> ");
Printf ("\ n ");
Return 0;
}

DWORD showfileattributes (lpstr szpath)
{
// File Attribute Structure
Win32_file_attribute_data wfad;
Printf ("file: % s \ n", szpath );
// Get file attributes
If (! Getfileattributesex (szpath, getfileexinfostandard, & wfad ))
{
Printf ("File Attribute retrieval error: % d \ n", getlasterror ());
Return 1;
}
// Display the related time
Printf ("Creation Time: \ t ");
Showfiletime (& (wfad. ftcreationtime ));
Printf ("last access time: \ t ");
Showfiletime (& (wfad. ftlastaccesstime ));
Printf ("last modification time: \ t ");
Showfiletime (& (wfad. ftlastwritetime ));
// Display the file size
Showfilesize (wfad. nfilesizehigh, wfad. nfilesizelow );
// Display file attributes
Showfileattrinfo (wfad. dwfileattributes );

Return 0;
}

Int main (pchar argv [])
{
Printf ("Enter the file path \ n ");
Scanf ("% s", argv );
Showfileattributes (argv [0]);
Printf ("display Parameters specify the attributes, time, and size of the file; \ n ");
Return 0;
}

This Program After running the program, a line of "Enter file path" is displayed, and the program crashes after you press enter in a path ............

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.