Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

INFORMATIONS SUR FICHIER (VC++ AVEC CFILE, OPENFILENAME) PAS DE GESTION D'ERREURS !!!!


Information sur la source

Catégorie :.Net Niveau : Débutant Date de création : 08/05/2002 Date de mise à jour : 08/05/2002 14:06:31 Vu : 4 079

Note :
10 / 10 - par 2 personnes
10,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

Description

un petit code pour connaitre les informations sur les fichiers , aucune erreurs sont gerées.le code utilise les classe de base Windows.
 

Source

  • <<InformationFichier.cpp>>
  • #include "stdafx.h"
  • #include<iostream>
  • #include <string>
  • #include <stdio.h>
  • #include "wingdi.h"
  • using namespace std;
  • enum attribute {
  • NORMAL = 0x00,
  • READONLY = 0x01,
  • HIDDEN = 0x02,
  • SYSTEM = 0x04,
  • VOLUME = 0x08,
  • DIRECTORY = 0x10,
  • ARCHIVE = 0x20
  • };
  • string Getattribut(char str);
  • int main(int argc, char* argv[])
  • {
  • OPENFILENAME Selection;
  • char Chemin[200];
  • char Fichier[50];
  • memset(&Selection,0,sizeof(Selection));
  • Selection.lStructSize =sizeof(OPENFILENAME);
  • Selection.hwndOwner=NULL;
  • Selection.hInstance=NULL;
  • Selection.lpstrFilter=
  • TEXT("Fichiers *.*\0*.*\0\0");
  • Selection.lpstrCustomFilter=NULL;
  • Selection.nMaxCustFilter=1;
  • Selection.nFilterIndex=1;
  • Selection.lpstrFile=Chemin;
  • Selection.nMaxFile=sizeof(Chemin);
  • Selection.lpstrFileTitle=Fichier;
  • Selection.nMaxFileTitle=sizeof(Fichier)-1;
  • Selection.lpstrInitialDir = NULL;
  • Selection.lpstrTitle="choisir un fichier";
  • Selection.Flags=OFN_FILEMUSTEXIST;
  • Selection.Flags=OFN_CREATEPROMPT;
  • Selection.lpstrDefExt =NULL;
  • Selection.lCustData=NULL;
  • Selection.lpfnHook=NULL;
  • Selection.lpTemplateName=NULL;
  • Chemin[0]='\0';
  • GetOpenFileName(&Selection);
  • if (Chemin!='\0'){
  • CFile file;
  • CFileException e;
  • CFileStatus status;
  • file.Open(Chemin,CFile::modeRead, &e);
  • file.GetStatus( Chemin, status );
  • cout<<"Chemin : "<<status.m_szFullName<<endl;
  • cout<<"///////////////////////////////////"<<endl;
  • cout<<"Taille en Octets :"<<status.m_size<<endl;
  • cout<<"///////////////////////////////////"<<endl;
  • cout<<"Atribut : "<<Getattribut(status.m_attribute)<<endl;
  • cout<<"///////////////////////////////////"<<endl;
  • cout<<"Fichier cree le : "<<status.m_ctime.GetDay()<<"/"<<status.m_ctime.GetMonth()<<"/"<<status.m_ctime.GetYear()<<endl ;
  • cout<<"///////////////////////////////////"<<endl;
  • cout<<"Fichier cree a : "<<status.m_ctime.GetHour() <<":"<<status.m_ctime.GetMinute()<<":"<<status.m_ctime.GetSecond()<<endl ;
  • cout<<"///////////////////////////////////"<<endl;
  • char pbuf[100];
  • UINT nBytesRead = file.Read( pbuf, 100 );
  • file.Close();
  • }
  • return 0;
  • }
  • string Getattribut(char str)
  • {
  • string attr1;
  • string attr2;
  • switch (str&0x0f)
  • {
  • case NORMAL:
  • attr1="normal";
  • break;
  • case READONLY:
  • attr1="lecture seule ";
  • break;
  • case HIDDEN:
  • attr1="cache";
  • break;
  • case SYSTEM:
  • attr1="system";
  • break;
  • case VOLUME:
  • attr1="volume";
  • break;
  • case HIDDEN+READONLY:
  • attr1=" cache + lecture seule ";
  • break;
  • case HIDDEN +SYSTEM:
  • attr1=" cache+systeme";
  • break;
  • case HIDDEN +VOLUME:
  • attr1=" cache + volume";
  • break;
  • case SYSTEM +VOLUME:
  • attr1=" systeme + volume";
  • break;
  • case HIDDEN + SYSTEM +VOLUME+READONLY:
  • attr1=" cache + systeme + volume + lecture seule";
  • break;
  • case HIDDEN + SYSTEM +VOLUME:
  • attr1="cache + systeme + volume";
  • break;
  • }
  • switch (str&0xf0)
  • {
  • case DIRECTORY:
  • attr2="repertoire";
  • break;
  • case ARCHIVE:
  • attr2="archive";
  • break;
  • }
  • return attr1+" + " +attr2;
  • }
  • <<stdafx.h>>
  • // stdafx.h : include file for standard system include files,
  • // or project specific include files that are used frequently, but
  • // are changed infrequently
  • //
  • #if !defined(AFX_STDAFX_H__080A3C04_6281_11D6_AEA2_0080C8DFB15E__INCLUDED_)
  • #define AFX_STDAFX_H__080A3C04_6281_11D6_AEA2_0080C8DFB15E__INCLUDED_
  • #if _MSC_VER > 1000
  • #pragma once
  • #endif // _MSC_VER > 1000
  • #include <afxwin.h> // MFC core and standard components
  • #include <afxext.h> // MFC extensions
  • #include <afxdisp.h> // MFC Automation classes
  • #include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
  • // TODO: reference additional headers your program requires here
  • //{{AFX_INSERT_LOCATION}}
  • // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  • #endif // !defined(AFX_STDAFX_H__080A3C04_6281_11D6_AEA2_0080C8DFB15E__INCLUDED_)
<<InformationFichier.cpp>>


#include "stdafx.h"
#include<iostream>
#include <string>
#include <stdio.h>
#include "wingdi.h"
using namespace std;
enum attribute {
   NORMAL =    0x00,
   READONLY =  0x01,
   HIDDEN =    0x02,
   SYSTEM =    0x04,
   VOLUME =    0x08,
   DIRECTORY = 0x10,
   ARCHIVE =   0x20
   };

string Getattribut(char str);
int main(int argc, char* argv[])
{
	OPENFILENAME Selection;
	char Chemin[200];
	char Fichier[50];

	memset(&Selection,0,sizeof(Selection));

	Selection.lStructSize =sizeof(OPENFILENAME);
	Selection.hwndOwner=NULL;
	Selection.hInstance=NULL;

	Selection.lpstrFilter=
	TEXT("Fichiers *.*\0*.*\0\0");

	Selection.lpstrCustomFilter=NULL;
	Selection.nMaxCustFilter=1;
	Selection.nFilterIndex=1;
	Selection.lpstrFile=Chemin;
	Selection.nMaxFile=sizeof(Chemin);
	Selection.lpstrFileTitle=Fichier;
	Selection.nMaxFileTitle=sizeof(Fichier)-1;
	Selection.lpstrInitialDir = NULL;
	Selection.lpstrTitle="choisir un fichier";
	Selection.Flags=OFN_FILEMUSTEXIST; 
	Selection.Flags=OFN_CREATEPROMPT; 
	Selection.lpstrDefExt =NULL;
	Selection.lCustData=NULL;
	Selection.lpfnHook=NULL;
	Selection.lpTemplateName=NULL;
	Chemin[0]='\0';
	GetOpenFileName(&Selection);
	if (Chemin!='\0'){
	 CFile file;
	CFileException e;
	CFileStatus status;
	file.Open(Chemin,CFile::modeRead, &e);
	file.GetStatus( Chemin, status );

		cout<<"Chemin : "<<status.m_szFullName<<endl;
		cout<<"///////////////////////////////////"<<endl;
		cout<<"Taille en Octets :"<<status.m_size<<endl;
		cout<<"///////////////////////////////////"<<endl;
		cout<<"Atribut : "<<Getattribut(status.m_attribute)<<endl;
		cout<<"///////////////////////////////////"<<endl;
		cout<<"Fichier cree le : "<<status.m_ctime.GetDay()<<"/"<<status.m_ctime.GetMonth()<<"/"<<status.m_ctime.GetYear()<<endl ;
		cout<<"///////////////////////////////////"<<endl;
		cout<<"Fichier cree a : "<<status.m_ctime.GetHour() <<":"<<status.m_ctime.GetMinute()<<":"<<status.m_ctime.GetSecond()<<endl ;
		cout<<"///////////////////////////////////"<<endl;


	char pbuf[100];
	UINT nBytesRead = file.Read( pbuf, 100 );

	file.Close();
	}
	return 0;
}

string Getattribut(char str)
{
	string attr1;
	string attr2;
	switch (str&0x0f)
	{
	case NORMAL:
		attr1="normal";
		break;

	case READONLY:
		attr1="lecture seule ";
		break;

	case    HIDDEN:
		attr1="cache";
		break;

	case SYSTEM:
		attr1="system";
		break;

	case VOLUME:
		attr1="volume";
		break;
	case HIDDEN+READONLY:
		attr1=" cache + lecture seule ";
		break;
	case HIDDEN +SYSTEM:
		attr1=" cache+systeme";
		break;
	case HIDDEN +VOLUME:
			attr1=" cache + volume";
			break;
	case SYSTEM +VOLUME:
				attr1=" systeme + volume";
				break;
	case HIDDEN + SYSTEM +VOLUME+READONLY:
				attr1=" cache + systeme + volume + lecture seule";
				break;
	case HIDDEN + SYSTEM +VOLUME:
		attr1="cache + systeme + volume";
		break;


	}
	switch (str&0xf0)
	{
	case DIRECTORY:
		attr2="repertoire";
		break;

	case ARCHIVE:
		attr2="archive";
		break;
	}

	return attr1+" + " +attr2;
}


<<stdafx.h>>

// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//      are changed infrequently
//

#if !defined(AFX_STDAFX_H__080A3C04_6281_11D6_AEA2_0080C8DFB15E__INCLUDED_)
#define AFX_STDAFX_H__080A3C04_6281_11D6_AEA2_0080C8DFB15E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxdisp.h>        // MFC Automation classes
#include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls

// TODO: reference additional headers your program requires here

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__080A3C04_6281_11D6_AEA2_0080C8DFB15E__INCLUDED_)
 

Conclusion

les seuls buggs viennent de la non gestion des erreurs !!!!!
 

Commentaires et avis

Aucun commentaire pour le moment.

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Septembre 2008
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
2930     

Consulter la suite du CalendriCode



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,22 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.