CFileFind クラスCFileFind Class
ローカルファイル検索を実行します。これは、インターネットファイル検索を実行する CGopherFileFind と CFtpFileFindの基本クラスです。Performs local file searches and is the base class for CGopherFileFind and CFtpFileFind, which perform Internet file searches.
構文Syntax
class CFileFind : public CObject
メンバーMembers
パブリック コンストラクターPublic Constructors
名前Name | 説明Description |
---|---|
CFileFind::CFileFindCFileFind::CFileFind | CFileFind オブジェクトを構築します。Constructs a CFileFind object. |
パブリック メソッドPublic Methods
名前Name | 説明Description |
---|---|
CFileFind:: CloseCFileFind::Close | 検索要求を閉じます。Closes the search request. |
CFileFind:: FindFileCFileFind::FindFile | 指定されたファイル名をディレクトリで検索します。Searches a directory for a specified file name. |
CFileFind::FindNextFileCFileFind::FindNextFile | 以前の FindFileの呼び出しからファイル検索を続行します。Continues a file search from a previous call to FindFile. |
CFileFind:: Get TimeCFileFind::GetCreationTime | ファイルが作成された時刻を取得します。Gets the time the file was created. |
CFileFind:: GetFileNameCFileFind::GetFileName | 検出されたファイルの名前 (拡張子を含む) を取得します。Gets the name, including the extension, of the found file |
CFileFind:: GetFilePathCFileFind::GetFilePath | 検出されたファイルの完全なパスを取得します。Gets the whole path of the found file. |
CFileFind::GetFileTitleCFileFind::GetFileTitle | 検出されたファイルのタイトルを取得します。Gets the title of the found file. タイトルには、拡張子は含まれません。The title does not include the extension. |
CFileFind::GetFileURLCFileFind::GetFileURL | 検出されたファイルの URL (ファイルパスを含む) を取得します。Gets the URL, including the file path, of the found file. |
CFileFind:: GetLastAccessTimeCFileFind::GetLastAccessTime | ファイルが最後にアクセスされた時刻を取得します。Gets the time that the file was last accessed. |
CFileFind:: GetLastWriteTimeCFileFind::GetLastWriteTime | ファイルが最後に変更されて保存された時刻を取得します。Gets the time the file was last changed and saved. |
CFileFind:: GetLengthCFileFind::GetLength | 検出されたファイルの長さをバイト単位で取得します。Gets the length of the found file, in bytes. |
CFileFind:: GetRootCFileFind::GetRoot | 検出されたファイルのルートディレクトリを取得します。Gets the root directory of the found file. |
CFileFind:: IsArchived 済みCFileFind::IsArchived | 検出されたファイルがアーカイブされているかどうかを判断します。Determines if the found file is archived. |
CFileFind:: IsCompressedCFileFind::IsCompressed | 検出されたファイルが圧縮されているかどうかを判断します。Determines if the found file is compressed. |
CFileFind:: IsDirectoryCFileFind::IsDirectory | 見つかったファイルがディレクトリであるかどうかを判断します。Determines if the found file is a directory. |
CFileFind:: IsDotsCFileFind::IsDots | 見つかったファイルの名前の名前が "." または ".." であるかどうかを判断します。これは、が実際にはディレクトリであることを示します。Determines if the name of the found file has the name "." or "..", indicating that is actually a directory. |
CFileFind:: IsHiddenCFileFind::IsHidden | 検出されたファイルが非表示かどうかを判断します。Determines if the found file is hidden. |
CFileFind:: IsNormalCFileFind::IsNormal | 検出されたファイルが正常であるかどうかを判断します (つまり、に他の属性はありません)。Determines if the found file is normal (in other words, has no other attributes). |
CFileFind:: IsReadOnlyCFileFind::IsReadOnly | 検出されたファイルが読み取り専用かどうかを判断します。Determines if the found file is read-only. |
CFileFind:: Issystem でCFileFind::IsSystem | 検出されたファイルがシステムファイルであるかどうかを判断します。Determines if the found file is a system file. |
CFileFind:: IsTemporaryCFileFind::IsTemporary | 見つかったファイルが一時的なものかどうかを判断します。Determines if the found file is temporary. |
CFileFind::MatchesMaskCFileFind::MatchesMask | 検索するファイルの必要なファイル属性を示します。Indicates the desired file attributes of the file to be found. |
プロテクト メソッドProtected Methods
名前Name | 説明Description |
---|---|
CFileFind:: CloのテキストCFileFind::CloseContext | 現在の検索ハンドルによって指定されたファイルを閉じます。Closes the file specified by the current search handle. |
プロテクト データ メンバーProtected Data Members
名前Name | 説明Description |
---|---|
CFileFind:: m_pTMCFileFind::m_pTM | オブジェクトへのポインター CAtlTransactionManager 。Pointer to a CAtlTransactionManager object. |
解説Remarks
CFileFind
には、検索を開始し、ファイルを検索し、ファイルのタイトル、名前、またはパスを返すメンバー関数が含まれています。CFileFind
includes member functions that begin a search, locate a file, and return the title, name, or path of the file. インターネット検索の場合、メンバー関数 GetFileURL はファイルの URL を返します。For Internet searches, the member function GetFileURL returns the file's URL.
CFileFind
は、特定のサーバーの種類を検索するように設計された、他の2つの MFC クラスの基本クラスです。これは CGopherFileFind
、特に gopher サーバーで機能し、 CFtpFileFind
FTP サーバーで特に機能します。CFileFind
is the base class for two other MFC classes designed to search particular server types: CGopherFileFind
works specifically with gopher servers, and CFtpFileFind
works specifically with FTP servers. これら3つのクラスは、サーバープロトコル、ファイルの種類、場所など、ローカルコンピューターまたはリモートサーバー上のファイルを検索するためのシームレスなメカニズムを提供します。Together, these three classes provide a seamless mechanism for the client to find files, regardless of the server protocol, the file type, or location, on either a local machine or a remote server.
次のコードでは、現在のディレクトリにあるすべてのファイルを列挙し、各ファイルの名前を出力します。The following code will enumerate all the files in the current directory, printing the name of each file:
CFileFind finder;
BOOL bWorking = finder.FindFile(_T("*.*"));
while (bWorking)
{
bWorking = finder.FindNextFile();
TRACE(_T("%s\n"), (LPCTSTR)finder.GetFileName());
}
例を単純にするために、このコードでは C++ 標準ライブラリクラスを使用して cout
います。To keep the example simple, this code uses the C++ Standard Library cout
class. この cout
行は CListBox::AddString
、グラフィカルユーザーインターフェイスを備えたプログラムで、などの呼び出しに置き換えることができます。The cout
line could be replaced with a call to CListBox::AddString
, for example, in a program with a graphical user interface.
とその他の WinInet クラスの使用方法の詳細については、 CFileFind
「 wininet を使用したインターネットプログラミング」を参照してください。For more information about how to use CFileFind
and the other WinInet classes, see the article Internet Programming with WinInet.
継承階層Inheritance Hierarchy
CFileFind
要件Requirements
ヘッダー: afxHeader: afx.h
CFileFind::CFileFindCFileFind::CFileFind
このメンバー関数は、オブジェクトが構築されるときに呼び出され CFileFind
ます。This member function is called when a CFileFind
object is constructed.
CFileFind();
CFileFind(CAtlTransactionManager* pTM);
パラメーターParameters
pTMpTM
CAtlTransactionManager オブジェクトへのポインター。Pointer to CAtlTransactionManager object
例Example
CFileFind:: GetFileNameの例を参照してください。See the example for CFileFind::GetFileName.
CFileFind:: CloseCFileFind::Close
検索を終了し、コンテキストをリセットし、すべてのリソースを解放するには、このメンバー関数を呼び出します。Call this member function to end the search, reset the context, and release all resources.
void Close();
解説Remarks
を呼び出した後 Close
、 CFileFind
FindFile を呼び出して新しい検索を開始する前に、新しいインスタンスを作成する必要はありません。After calling Close
, you do not have to create a new CFileFind
instance before calling FindFile to begin a new search.
例Example
CFileFind:: GetFileNameの例を参照してください。See the example for CFileFind::GetFileName.
CFileFind:: CloのテキストCFileFind::CloseContext
現在の検索ハンドルによって指定されたファイルを閉じます。Closes the file specified by the current search handle.
virtual void CloseContext();
解説Remarks
検索ハンドルの現在の値によって指定されたファイルを閉じます。Closes the file specified by the current value of the search handle. 既定の動作を変更するには、この関数をオーバーライドします。Override this function to change the default behavior.
有効な検索ハンドルを取得するには、少なくとも1回は FindFile 関数または FindNextFile 関数を呼び出す必要があります。You must call the FindFile or FindNextFile functions at least once to retrieve a valid search handle. FindFile
関数と関数は、検索ハンドルを使用して、 FindNextFile
指定された名前に一致する名前を持つファイルを検索します。The FindFile
and FindNextFile
functions use the search handle to locate files with names that match a given name.
CFileFind:: FindFileCFileFind::FindFile
ファイル検索を開くには、このメンバー関数を呼び出します。Call this member function to open a file search.
virtual BOOL FindFile(
LPCTSTR pstrName = NULL,
DWORD dwUnused = 0);
パラメーターParameters
pstrNamepstrName
検索するファイルの名前を格納している文字列へのポインター。A pointer to a string containing the name of the file to find. Pstrname に NULL を渡すと、 FindFile
はワイルドカード (*. * ) 検索を行います。If you pass NULL for pstrName, FindFile
does a wildcard (*.*) search.
dwUnuseddwUnused
派生クラスでポリモーフィックにするために予約さ FindFile
れています。Reserved to make FindFile
polymorphic with derived classes. 0 を指定する必要があります。Must be 0.
戻り値Return Value
正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。Nonzero if successful; otherwise 0. 拡張されたエラー情報を取得するには、Win32 関数 GetLastErrorを呼び出します。To get extended error information, call the Win32 function GetLastError.
解説Remarks
を呼び出し FindFile
てファイル検索を開始した後、 FindNextFile を呼び出して後続のファイルを取得します。After calling FindFile
to begin the file search, call FindNextFile to retrieve subsequent files. FindNextFile
次の属性メンバー関数のいずれかを呼び出す前に、を少なくとも1回呼び出す必要があります。You must call FindNextFile
at least once before calling any of the following attribute member functions:
例Example
CFileFind:: IsDirectoryの例を参照してください。See the example for CFileFind::IsDirectory.
CFileFind::FindNextFileCFileFind::FindNextFile
以前の FindFileの呼び出しからファイル検索を続行するには、このメンバー関数を呼び出します。Call this member function to continue a file search from a previous call to FindFile.
virtual BOOL FindNextFile();
戻り値Return Value
他のファイルがある場合は0以外。見つかったファイルがディレクトリ内の最後のファイルであるか、エラーが発生した場合は0。Nonzero if there are more files; zero if the file found is the last one in the directory or if an error occurred. 拡張されたエラー情報を取得するには、Win32 関数 GetLastErrorを呼び出します。To get extended error information, call the Win32 function GetLastError. 見つかったファイルがディレクトリ内の最後のファイルである場合、または一致するファイルが見つからない場合、 GetLastError
関数は ERROR_NO_MORE_FILES を返します。If the file found is the last file in the directory, or if no matching files can be found, the GetLastError
function returns ERROR_NO_MORE_FILES.
解説Remarks
FindNextFile
次の属性メンバー関数のいずれかを呼び出す前に、を少なくとも1回呼び出す必要があります。You must call FindNextFile
at least once before calling any of the following attribute member functions:
FindNextFile
Win32 関数 FindNextFileをラップします。FindNextFile
wraps the Win32 function FindNextFile.
例Example
CFileFind:: IsDirectoryの例を参照してください。See the example for CFileFind::IsDirectory.
CFileFind:: Get TimeCFileFind::GetCreationTime
このメンバー関数を呼び出して、指定したファイルが作成された時刻を取得します。Call this member function to get the time the specified file was created.
virtual BOOL GetCreationTime(FILETIME* pTimeStamp) const;
virtual BOOL GetCreationTime(CTime& refTime) const;
パラメーターParameters
pTimeStamppTimeStamp
ファイルが作成された時刻を格納している FILETIME 構造体へのポインター。A pointer to a FILETIME structure containing the time the file was created.
refTimerefTime
CTimeオブジェクトへの参照。A reference to a CTime object.
戻り値Return Value
成功した場合は0以外の。失敗した場合は0。Nonzero if successful; 0 if unsuccessful. GetCreationTime
このオブジェクトで FindNextFile が呼び出されたことがない場合にのみ、0を返し CFileFind
ます。GetCreationTime
returns 0 only if FindNextFile has never been called on this CFileFind
object.
解説Remarks
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり GetCreationTime
ます。You must call FindNextFile at least once before calling GetCreationTime
.
注意
すべてのファイルシステムで同じセマンティクスを使用して、この関数によって返されるタイムスタンプが実装されるわけではありません。Not all file systems use the same semantics to implement the time stamp returned by this function. 基になるファイルシステムまたはサーバーが time 属性の保持をサポートしていない場合、この関数は、他のタイムスタンプ関数から返される値と同じ値を返すことがあります。This function may return the same value returned by other time stamp functions if the underlying file system or server does not support keeping the time attribute. 時刻形式の詳細については、 WIN32_FIND_DATA 構造体を参照してください。See the WIN32_FIND_DATA structure for information about time formats. 一部のオペレーティングシステムでは、返された時間は、コンピューターのローカルのタイムゾーンのファイルの場所にあります。On some operation systems, the returned time is in the time zone local to the machine were the file is located. 詳細については、Win32 FileTimeToLocalFileTime API に関する説明を参照してください。See the Win32 FileTimeToLocalFileTime API for more information.
例Example
CFileFind:: GetLengthの例を参照してください。See the example for CFileFind::GetLength.
CFileFind:: GetFileNameCFileFind::GetFileName
検出されたファイルの名前を取得するには、このメンバー関数を呼び出します。Call this member function to get the name of the found file.
virtual CString GetFileName() const;
戻り値Return Value
最近検出されたファイルの名前。The name of the most-recently-found file.
解説Remarks
GetFileName を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があります。You must call FindNextFile at least once before calling GetFileName.
GetFileName
は CFileFind
、何らかの形式のファイル名を返す3つのメンバー関数のうちの1つです。GetFileName
is one of three CFileFind
member functions that return some form of the file name. 次の一覧では、3つの方法とそれらの違いについて説明します。The following list describes the three and how they vary:
GetFileName
拡張子を含むファイル名を返します。GetFileName
returns the file name, including the extension. たとえば、を呼び出しGetFileName
て、ファイル c:\myhtml\myfile.txt に関するユーザーメッセージを生成すると、 myfile.txt ファイル名が返されます。For example, callingGetFileName
to generate a user message about the file c:\myhtml\myfile.txt returns the file name myfile.txt.Getfilepath は、ファイルのパス全体を返します。GetFilePath returns the entire path for the file. たとえば、を呼び出すと、ファイル
GetFilePath
c:\myhtml\myfile.txt に関するユーザーメッセージが生成され、 c:\myhtml\myfile.txt ファイルパスが返されます。For example, callingGetFilePath
to generate a user message about the file c:\myhtml\myfile.txt returns the file path c:\myhtml\myfile.txt.GetFileTitle はファイル名を返します (ファイル拡張子は除く)。GetFileTitle returns the file name, excluding the file extension. たとえば、を呼び出すと、ファイル
GetFileTitle
の c:\myhtml\myfile.txt に関するユーザーメッセージが生成さ れ ます。For example, callingGetFileTitle
to generate a user message about the file c:\myhtml\myfile.txt returns the file title myfile.
例Example
CFileFind finder;
static const TCHAR szFileToFind[] = _T("C:\\WINDOWS\\SYSTEM.INI");
BOOL bResult = finder.FindFile(szFileToFind);
if (bResult)
{
finder.FindNextFile();
TRACE(_T("Root of %s is %s\n"), szFileToFind,
(LPCTSTR)finder.GetRoot());
TRACE(_T("Title of %s is %s\n"), szFileToFind,
(LPCTSTR)finder.GetFileTitle());
TRACE(_T("Path of %s is %s\n"), szFileToFind,
(LPCTSTR)finder.GetFilePath());
TRACE(_T("URL of %s is %s\n"), szFileToFind,
(LPCTSTR)finder.GetFileURL());
TRACE(_T("Name of %s is %s\n"), szFileToFind,
(LPCTSTR)finder.GetFileName());
finder.Close();
}
else
{
TRACE(_T("You have no %s file.\n"), szFileToFind);
}
CFileFind:: GetFilePathCFileFind::GetFilePath
このメンバー関数を呼び出して、指定したファイルの完全なパスを取得します。Call this member function to get the full path of the specified file.
virtual CString GetFilePath() const;
戻り値Return Value
指定したファイルのパス。The path of the specified file.
解説Remarks
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり GetFilePath
ます。You must call FindNextFile at least once before calling GetFilePath
.
GetFilePath
は CFileFind
、何らかの形式のファイル名を返す3つのメンバー関数のうちの1つです。GetFilePath
is one of three CFileFind
member functions that return some form of the file name. 次の一覧では、3つの方法とそれらの違いについて説明します。The following list describes the three and how they vary:
Getfilename は、拡張子を含むファイル名を返します。GetFileName returns the file name, including the extension. たとえば、を呼び出し
GetFileName
て、ファイル c:\myhtml\myfile.txt に関するユーザーメッセージを生成すると、 myfile.txt ファイル名が返されます。For example, callingGetFileName
to generate a user message about the file c:\myhtml\myfile.txt returns the file name myfile.txt.GetFilePath
ファイルのパス全体を返します。GetFilePath
returns the entire path for the file. たとえば、ファイルにGetFilePath
関するユーザーメッセージを生成するためにを呼び出すと、c:\myhtml\myfile.txt
ファイルパスが返されc:\myhtml\myfile.txt
ます。For example, callingGetFilePath
to generate a user message about the filec:\myhtml\myfile.txt
returns the file pathc:\myhtml\myfile.txt
.GetFileTitle はファイル名を返します (ファイル拡張子は除く)。GetFileTitle returns the file name, excluding the file extension. たとえば、を呼び出すと、ファイル
GetFileTitle
の c:\myhtml\myfile.txt に関するユーザーメッセージが生成さ れ ます。For example, callingGetFileTitle
to generate a user message about the file c:\myhtml\myfile.txt returns the file title myfile.
例Example
CFileFind:: GetFileNameの例を参照してください。See the example for CFileFind::GetFileName.
CFileFind::GetFileTitleCFileFind::GetFileTitle
検出されたファイルのタイトルを取得するには、このメンバー関数を呼び出します。Call this member function to get the title of the found file.
virtual CString GetFileTitle() const;
戻り値Return Value
ファイルのタイトル。The title of the file.
解説Remarks
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり GetFileTitle
ます。You must call FindNextFile at least once before calling GetFileTitle
.
GetFileTitle
は CFileFind
、何らかの形式のファイル名を返す3つのメンバー関数のうちの1つです。GetFileTitle
is one of three CFileFind
member functions that return some form of the file name. 次の一覧では、3つの方法とそれらの違いについて説明します。The following list describes the three and how they vary:
Getfilename は、拡張子を含むファイル名を返します。GetFileName returns the file name, including the extension. たとえば、を呼び出し
GetFileName
て、ファイル c:\myhtml\myfile.txt に関するユーザーメッセージを生成すると、 myfile.txt ファイル名が返されます。For example, callingGetFileName
to generate a user message about the file c:\myhtml\myfile.txt returns the file name myfile.txt.Getfilepath は、ファイルのパス全体を返します。GetFilePath returns the entire path for the file. たとえば、を呼び出すと、ファイル
GetFilePath
c:\myhtml\myfile.txt に関するユーザーメッセージが生成され、 c:\myhtml\myfile.txt ファイルパスが返されます。For example, callingGetFilePath
to generate a user message about the file c:\myhtml\myfile.txt returns the file path c:\myhtml\myfile.txt.GetFileTitle
ファイル名を返します (ファイル拡張子は除く)。GetFileTitle
returns the file name, excluding the file extension. たとえば、を呼び出すと、ファイルGetFileTitle
の c:\myhtml\myfile.txt に関するユーザーメッセージが生成さ れ ます。For example, callingGetFileTitle
to generate a user message about the file c:\myhtml\myfile.txt returns the file title myfile.
例Example
CFileFind:: GetFileNameの例を参照してください。See the example for CFileFind::GetFileName.
CFileFind::GetFileURLCFileFind::GetFileURL
指定した URL を取得するには、このメンバー関数を呼び出します。Call this member function to retrieve the specified URL.
virtual CString GetFileURL() const;
戻り値Return Value
完全な URL。The complete URL.
解説Remarks
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり GetFileURL
ます。You must call FindNextFile at least once before calling GetFileURL
.
GetFileURL
は、という形式の URL を返す点を除けば、メンバー関数 Getfilepathに似てい file://path
ます。GetFileURL
is similar to the member function GetFilePath, except that it returns the URL in the form file://path
. たとえば、を呼び出して GetFileURL
myfile.txt の完全な url を取得すると、url が返され file://c:\myhtml\myfile.txt
ます。For example, calling GetFileURL
to get the complete URL for myfile.txt returns the URL file://c:\myhtml\myfile.txt
.
例Example
CFileFind:: GetFileNameの例を参照してください。See the example for CFileFind::GetFileName.
CFileFind:: GetLastAccessTimeCFileFind::GetLastAccessTime
このメンバー関数を呼び出して、指定したファイルに最後にアクセスした時刻を取得します。Call this member function to get the time that the specified file was last accessed.
virtual BOOL GetLastAccessTime(CTime& refTime) const;
virtual BOOL GetLastAccessTime(FILETIME* pTimeStamp) const;
パラメーターParameters
refTimerefTime
CTimeオブジェクトへの参照。A reference to a CTime object.
pTimeStamppTimeStamp
ファイルが最後にアクセスされた時刻を格納している FILETIME 構造体へのポインター。A pointer to a FILETIME structure containing the time the file was last accessed.
戻り値Return Value
成功した場合は0以外の。失敗した場合は0。Nonzero if successful; 0 if unsuccessful. GetLastAccessTime
このオブジェクトで FindNextFile が呼び出されたことがない場合にのみ、0を返し CFileFind
ます。GetLastAccessTime
returns 0 only if FindNextFile has never been called on this CFileFind
object.
解説Remarks
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり GetLastAccessTime
ます。You must call FindNextFile at least once before calling GetLastAccessTime
.
注意
すべてのファイルシステムで同じセマンティクスを使用して、この関数によって返されるタイムスタンプが実装されるわけではありません。Not all file systems use the same semantics to implement the time stamp returned by this function. 基になるファイルシステムまたはサーバーが time 属性の保持をサポートしていない場合、この関数は、他のタイムスタンプ関数から返される値と同じ値を返すことがあります。This function may return the same value returned by other time stamp functions if the underlying file system or server does not support keeping the time attribute. 時刻形式の詳細については、 WIN32_FIND_DATA 構造体を参照してください。See the WIN32_FIND_DATA structure for information about time formats. 一部のオペレーティングシステムでは、返された時間は、コンピューターのローカルのタイムゾーンのファイルの場所にあります。On some operation systems, the returned time is in the time zone local to the machine were the file is located. 詳細については、Win32 FileTimeToLocalFileTime API に関する説明を参照してください。See the Win32 FileTimeToLocalFileTime API for more information.
例Example
CFileFind:: GetLengthの例を参照してください。See the example for CFileFind::GetLength.
CFileFind:: GetLastWriteTimeCFileFind::GetLastWriteTime
ファイルが最後に変更された時刻を取得するには、このメンバー関数を呼び出します。Call this member function to get the last time the file was changed.
virtual BOOL GetLastWriteTime(FILETIME* pTimeStamp) const;
virtual BOOL GetLastWriteTime(CTime& refTime) const;
パラメーターParameters
pTimeStamppTimeStamp
ファイルが最後に書き込まれた時刻を格納している FILETIME 構造体へのポインター。A pointer to a FILETIME structure containing the time the file was last written to.
refTimerefTime
CTimeオブジェクトへの参照。A reference to a CTime object.
戻り値Return Value
成功した場合は0以外の。失敗した場合は0。Nonzero if successful; 0 if unsuccessful. GetLastWriteTime
このオブジェクトで FindNextFile が呼び出されたことがない場合にのみ、0を返し CFileFind
ます。GetLastWriteTime
returns 0 only if FindNextFile has never been called on this CFileFind
object.
解説Remarks
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり GetLastWriteTime
ます。You must call FindNextFile at least once before calling GetLastWriteTime
.
注意
すべてのファイルシステムで同じセマンティクスを使用して、この関数によって返されるタイムスタンプが実装されるわけではありません。Not all file systems use the same semantics to implement the time stamp returned by this function. 基になるファイルシステムまたはサーバーが time 属性の保持をサポートしていない場合、この関数は、他のタイムスタンプ関数から返される値と同じ値を返すことがあります。This function may return the same value returned by other time stamp functions if the underlying file system or server does not support keeping the time attribute. 時刻形式の詳細については、 WIN32_FIND_DATA 構造体を参照してください。See the WIN32_FIND_DATA structure for information about time formats. 一部のオペレーティングシステムでは、返された時間は、コンピューターのローカルのタイムゾーンのファイルの場所にあります。On some operation systems, the returned time is in the time zone local to the machine were the file is located. 詳細については、Win32 FileTimeToLocalFileTime API に関する説明を参照してください。See the Win32 FileTimeToLocalFileTime API for more information.
例Example
CFileFind:: GetLengthの例を参照してください。See the example for CFileFind::GetLength.
CFileFind:: GetLengthCFileFind::GetLength
このメンバー関数を呼び出して、検出されたファイルの長さをバイト単位で取得します。Call this member function to get the length of the found file, in bytes.
ULONGLONG GetLength() const;
戻り値Return Value
検出されたファイルの長さ (バイト単位)。The length of the found file, in bytes.
解説Remarks
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり GetLength
ます。You must call FindNextFile at least once before calling GetLength
.
GetLength
Win32 構造体 WIN32_FIND_DATA を使用して、ファイルサイズの値を取得して返します (バイト単位)。GetLength
uses the Win32 structure WIN32_FIND_DATA to get and return the value of the file size, in bytes.
注意
MFC 7.0 の As では、は GetLength
64 ビットの整数型をサポートしています。As of MFC 7.0, GetLength
supports 64-bit integer types. この新しいバージョンのライブラリでビルドされた既存のコードでは、切り捨ての警告が発生する可能性があります。Previously existing code built with this newer version of the library may result in truncation warnings.
例Example
// This code fragment prints out a very verbose directory
// listing for all the files in the root directory on the
// C: drive. After the file's name, each attribute of the
// file is printed, as are the creation, last access, and
// last write times.
CFileFind finder;
BOOL bWorking = finder.FindFile(_T("C:\\*.*"));
while (bWorking)
{
bWorking = finder.FindNextFile();
_tprintf_s(_T("%s\n\t"), (LPCTSTR)finder.GetFileName());
_tprintf_s(_T("%c"), finder.IsArchived() ? 'A' : 'a');
_tprintf_s(_T("%c"), finder.IsCompressed() ? 'C' : 'c');
_tprintf_s(_T("%c"), finder.IsHidden() ? 'H' : 'h');
_tprintf_s(_T("%c"), finder.IsNormal() ? 'N' : 'n');
_tprintf_s(_T("%c"), finder.IsReadOnly() ? 'R' : 'r');
_tprintf_s(_T("%c"), finder.IsSystem() ? 'S' : 's');
_tprintf_s(_T("%c"), finder.IsTemporary() ? 'T' : 't');
_tprintf_s(_T("\t%I64u byte(s)\n"), finder.GetLength());
CTime tempTime;
CString str;
_tprintf_s(_T("\tCreated : "));
if (finder.GetCreationTime(tempTime))
{
str = tempTime.Format(_T("%c"));
_tprintf_s(_T("%s\n"), (LPCTSTR) str);
}
else
{
_tprintf_s(_T("(unavailable)\n"));
}
_tprintf_s(_T("\tLast Access: "));
if (finder.GetLastAccessTime(tempTime))
{
str = tempTime.Format(_T("%c"));
_tprintf_s(_T("%s\n"), (LPCTSTR) str);
}
else
{
_tprintf_s(_T("(unavailable)\n"));
}
_tprintf_s(_T("\tLast Write : "));
if (finder.GetLastWriteTime(tempTime))
{
str = tempTime.Format(_T("%c"));
_tprintf_s(_T("%s\n"), (LPCTSTR) str);
}
else
{
_tprintf_s(_T("(unavailable)\n"));
}
_tprintf_s(_T("\n"));
}
CFileFind:: GetRootCFileFind::GetRoot
検出されたファイルのルートを取得するには、このメンバー関数を呼び出します。Call this member function to get the root of the found file.
virtual CString GetRoot() const;
戻り値Return Value
アクティブな検索のルート。The root of the active search.
解説Remarks
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり GetRoot
ます。You must call FindNextFile at least once before calling GetRoot
.
このメンバー関数は、検索を開始するために使用されるドライブ指定子とパス名を返します。This member function returns the drive specifier and path name used to start a search. たとえば、を指定して FindFile を呼び出すと、によって *.dat
GetRoot
空の文字列が返されます。For example, calling FindFile with *.dat
results in GetRoot
returning an empty string. などのパスを c:\windows\system\*.dll
結果に渡す FindFile
GetRoot
c:\windows\system\
。Passing a path, such as c:\windows\system\*.dll
, to FindFile
results GetRoot
returning c:\windows\system\
.
例Example
CFileFind:: GetFileNameの例を参照してください。See the example for CFileFind::GetFileName.
CFileFind:: IsArchived 済みCFileFind::IsArchived
見つかったファイルがアーカイブされているかどうかを判断するには、このメンバー関数を呼び出します。Call this member function to determine if the found file is archived.
BOOL IsArchived() const;
戻り値Return Value
正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。Nonzero if successful; otherwise 0.
解説Remarks
アプリケーションは、バックアップまたは削除されるアーカイブファイルを、 WIN32_FIND_DATA 構造体で指定されたファイル属性 FILE_ATTRIBUTE_ARCHIVE でマークします。Applications mark an archive file, which is to be backed up or removed, with FILE_ATTRIBUTE_ARCHIVE, a file attribute identified in the WIN32_FIND_DATA structure.
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり IsArchived
ます。You must call FindNextFile at least once before calling IsArchived
.
ファイル属性の完全な一覧については、「メンバー関数 MatchesMask 」を参照してください。See the member function MatchesMask for a complete list of file attributes.
例Example
CFileFind:: GetLengthの例を参照してください。See the example for CFileFind::GetLength.
CFileFind:: IsCompressedCFileFind::IsCompressed
見つかったファイルが圧縮されているかどうかを判断するには、このメンバー関数を呼び出します。Call this member function to determine if the found file is compressed.
BOOL IsCompressed() const;
戻り値Return Value
正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。Nonzero if successful; otherwise 0.
解説Remarks
圧縮ファイルは、 WIN32_FIND_DATA 構造で識別されたファイル属性である FILE_ATTRIBUTE_COMPRESSED でマークされます。A compressed file is marked with FILE_ATTRIBUTE_COMPRESSED, a file attribute identified in the WIN32_FIND_DATA structure. ファイルの場合、この属性はファイル内のすべてのデータが圧縮されていることを示します。For a file, this attribute indicates that all of the data in the file is compressed. ディレクトリの場合、この属性は、新しく作成されたファイルおよびサブディレクトリの圧縮が既定値であることを示します。For a directory, this attribute indicates that compression is the default for newly created files and subdirectories.
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり IsCompressed
ます。You must call FindNextFile at least once before calling IsCompressed
.
ファイル属性の完全な一覧については、「メンバー関数 MatchesMask 」を参照してください。See the member function MatchesMask for a complete list of file attributes.
例Example
CFileFind:: GetLengthの例を参照してください。See the example for CFileFind::GetLength.
CFileFind:: IsDirectoryCFileFind::IsDirectory
見つかったファイルがディレクトリであるかどうかを判断するには、このメンバー関数を呼び出します。Call this member function to determine if the found file is a directory.
BOOL IsDirectory() const;
戻り値Return Value
正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。Nonzero if successful; otherwise 0.
解説Remarks
ディレクトリであるファイルは、 WIN32_FIND_DATA 構造で識別されたファイル属性 FILE_ATTRIBUTE_DIRECTORY でマークされます。A file that is a directory is marked with FILE_ATTRIBUTE_DIRECTORY a file attribute identified in the WIN32_FIND_DATA structure.
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり IsDirectory
ます。You must call FindNextFile at least once before calling IsDirectory
.
ファイル属性の完全な一覧については、「メンバー関数 MatchesMask 」を参照してください。See the member function MatchesMask for a complete list of file attributes.
例Example
この小さなプログラムは、C:\ 上のすべてのディレクトリを繰り返しします。ディレクトリの名前をドライブに出力します。This small program recurses every directory on the C:\ drive and prints the name of the directory.
void Recurse(LPCTSTR pstr)
{
CFileFind finder;
// build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T("\\*.*");
// start working for files
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking)
{
bWorking = finder.FindNextFile();
// skip . and .. files; otherwise, we'd
// recur infinitely!
if (finder.IsDots())
continue;
// if it's a directory, recursively search it
if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
TRACE(_T("%s\n"), (LPCTSTR)str);
Recurse(str);
}
}
finder.Close();
}
void PrintDirs()
{
Recurse(_T("C:"));
}
CFileFind:: IsDotsCFileFind::IsDots
ファイルの反復処理中に現在のディレクトリマーカーと親ディレクトリマーカーをテストするには、このメンバー関数を呼び出します。Call this member function to test for the current directory and parent directory markers while iterating through files.
virtual BOOL IsDots() const;
戻り値Return Value
見つかったファイルの名前が "." または ".." である場合は0以外の値。見つかったファイルが実際にはディレクトリであることを示します。Nonzero if the found file has the name "." or "..", which indicates that the found file is actually a directory. それ以外の場合は0です。Otherwise 0.
解説Remarks
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり IsDots
ます。You must call FindNextFile at least once before calling IsDots
.
例Example
CFileFind:: IsDirectoryの例を参照してください。See the example for CFileFind::IsDirectory.
CFileFind:: IsHiddenCFileFind::IsHidden
検出されたファイルが非表示かどうかを判断するには、このメンバー関数を呼び出します。Call this member function to determine if the found file is hidden.
BOOL IsHidden() const;
戻り値Return Value
正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。Nonzero if successful; otherwise 0.
解説Remarks
FILE_ATTRIBUTE_HIDDEN でマークされている隠しファイルは、 WIN32_FIND_DATA 構造で識別されたファイル属性です。Hidden files, which are marked with FILE_ATTRIBUTE_HIDDEN, a file attribute identified in the WIN32_FIND_DATA structure. 隠しファイルは、通常のディレクトリの一覧には含まれません。A hidden file is not included in an ordinary directory listing.
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり IsHidden
ます。You must call FindNextFile at least once before calling IsHidden
.
ファイル属性の完全な一覧については、「メンバー関数 MatchesMask 」を参照してください。See the member function MatchesMask for a complete list of file attributes.
例Example
CFileFind:: GetLengthの例を参照してください。See the example for CFileFind::GetLength.
CFileFind:: IsNormalCFileFind::IsNormal
見つかったファイルが通常のファイルであるかどうかを判断するには、このメンバー関数を呼び出します。Call this member function to determine if the found file is a normal file.
BOOL IsNormal() const;
戻り値Return Value
正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。Nonzero if successful; otherwise 0.
解説Remarks
FILE_ATTRIBUTE_NORMAL でマークされたファイル。 WIN32_FIND_DATA 構造体で識別されるファイル属性です。Files marked with FILE_ATTRIBUTE_NORMAL, a file attribute identified in the WIN32_FIND_DATA structure. 通常のファイルには、他の属性は設定されていません。A normal file has no other attributes set. 他のすべてのファイル属性は、この属性をオーバーライドします。All other file attributes override this attribute.
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり IsNormal
ます。You must call FindNextFile at least once before calling IsNormal
.
ファイル属性の完全な一覧については、「メンバー関数 MatchesMask 」を参照してください。See the member function MatchesMask for a complete list of file attributes.
例Example
CFileFind:: GetLengthの例を参照してください。See the example for CFileFind::GetLength.
CFileFind:: IsReadOnlyCFileFind::IsReadOnly
検出されたファイルが読み取り専用かどうかを判断するには、このメンバー関数を呼び出します。Call this member function to determine if the found file is read-only.
BOOL IsReadOnly() const;
戻り値Return Value
正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。Nonzero if successful; otherwise 0.
解説Remarks
読み取り専用ファイルは、 WIN32_FIND_DATA 構造で識別されたファイル属性 FILE_ATTRIBUTE_READONLY でマークされます。A read-only file is marked with FILE_ATTRIBUTE_READONLY, a file attribute identified in the WIN32_FIND_DATA structure. アプリケーションはこのようなファイルを読み取ることができますが、書き込みや削除を行うことはできません。Applications can read such a file, but they cannot write to it or delete it.
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり IsReadOnly
ます。You must call FindNextFile at least once before calling IsReadOnly
.
ファイル属性の完全な一覧については、「メンバー関数 MatchesMask 」を参照してください。See the member function MatchesMask for a complete list of file attributes.
例Example
CFileFind:: GetLengthの例を参照してください。See the example for CFileFind::GetLength.
CFileFind:: Issystem でCFileFind::IsSystem
検出されたファイルがシステムファイルであるかどうかを判断するには、このメンバー関数を呼び出します。Call this member function to determine if the found file is a system file.
BOOL IsSystem() const;
戻り値Return Value
正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。Nonzero if successful; otherwise 0.
解説Remarks
システムファイルは FILE_ATTRIBUTE_SYSTEM でマークされます。これは、 WIN32_FIND_DATA 構造体で識別されるファイル属性です。A system file is marked with FILE_ATTRIBUTE_SYSTEM, , a file attribute identified in the WIN32_FIND_DATA structure. システムファイルは、オペレーティングシステムの一部であるか、オペレーティングシステムによって排他的に使用されます。A system file is part of, or is used exclusively by, the operating system.
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり IsSystem
ます。You must call FindNextFile at least once before calling IsSystem
.
ファイル属性の完全な一覧については、「メンバー関数 MatchesMask 」を参照してください。See the member function MatchesMask for a complete list of file attributes.
例Example
CFileFind:: GetLengthの例を参照してください。See the example for CFileFind::GetLength.
CFileFind:: IsTemporaryCFileFind::IsTemporary
このメンバー関数を呼び出して、見つかったファイルが一時ファイルであるかどうかを確認します。Call this member function to determine if the found file is a temporary file.
BOOL IsTemporary() const;
戻り値Return Value
正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。Nonzero if successful; otherwise 0.
解説Remarks
一時ファイルは、 WIN32_FIND_DATA 構造で識別されたファイル属性である FILE_ATTRIBUTE_TEMPORARY でマークされます。A temporary file is marked with FILE_ATTRIBUTE_TEMPORARY, a file attribute identified in the WIN32_FIND_DATA structure. 一時ストレージには一時ファイルが使用されます。A temporary file is used for temporary storage. アプリケーションは、絶対に必要な場合にのみファイルに書き込む必要があります。Applications should write to the file only if absolutely necessary. ファイルはすぐに削除されるため、ファイルのデータのほとんどは、メディアにフラッシュされることなくメモリに残ります。Most of the file's data remains in memory without being flushed to the media because the file will soon be deleted.
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり IsTemporary
ます。You must call FindNextFile at least once before calling IsTemporary
.
ファイル属性の完全な一覧については、「メンバー関数 MatchesMask 」を参照してください。See the member function MatchesMask for a complete list of file attributes.
例Example
CFileFind:: GetLengthの例を参照してください。See the example for CFileFind::GetLength.
CFileFind:: m_pTMCFileFind::m_pTM
オブジェクトへのポインター CAtlTransactionManager
。Pointer to a CAtlTransactionManager
object.
CAtlTransactionManager* m_pTM;
解説Remarks
CFileFind::MatchesMaskCFileFind::MatchesMask
検出されたファイルのファイル属性をテストするには、このメンバー関数を呼び出します。Call this member function to test the file attributes on the found file.
virtual BOOL MatchesMask(DWORD dwMask) const;
パラメーターParameters
dwMaskdwMask
検出されたファイルの WIN32_FIND_DATA 構造体で識別される1つ以上のファイル属性を指定します。Specifies one or more file attributes, identified in the WIN32_FIND_DATA structure, for the found file. 複数の属性を検索するには、ビットごとの OR (|) 演算子を使用します。To search for multiple attributes, use the bitwise OR (|) operator. 次の属性の任意の組み合わせを使用できます。Any combination of the following attributes is acceptable:
ファイルがアーカイブファイルで FILE_ATTRIBUTE_ARCHIVE。FILE_ATTRIBUTE_ARCHIVE The file is an archive file. アプリケーションでは、この属性を使用して、バックアップまたは削除するファイルをマークします。Applications use this attribute to mark files for backup or removal.
FILE_ATTRIBUTE_COMPRESSED ファイルまたはディレクトリが圧縮されていることを示します。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 ファイルがディレクトリであることを示します。FILE_ATTRIBUTE_DIRECTORY The file is a directory.
ファイルに他の属性が設定されていない FILE_ATTRIBUTE_NORMAL。FILE_ATTRIBUTE_NORMAL The file has no other attributes set. この属性は、単独で使用した場合にのみ有効です。This attribute is valid only if used alone. 他のすべてのファイル属性は、この属性をオーバーライドします。All other file attributes override this attribute.
FILE_ATTRIBUTE_HIDDEN ファイルが非表示になっています。FILE_ATTRIBUTE_HIDDEN The file is hidden. 通常のディレクトリの一覧に含めることはできません。It is not to be included in an ordinary directory listing.
FILE_ATTRIBUTE_READONLY ファイルは読み取り専用です。FILE_ATTRIBUTE_READONLY The file is read only. アプリケーションはファイルを読み取ることができますが、書き込むことや削除することはできません。Applications can read the file but cannot write to it or delete it.
ファイルがの一部であるか、オペレーティングシステムによって排他的に使用されて FILE_ATTRIBUTE_SYSTEM。FILE_ATTRIBUTE_SYSTEM The file is part of or is used exclusively by the operating system.
一時ストレージにファイルが使用されて FILE_ATTRIBUTE_TEMPORARY。FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. アプリケーションは、絶対に必要な場合にのみファイルに書き込む必要があります。Applications should write to the file only if absolutely necessary. ファイルはすぐに削除されるため、ファイルのデータのほとんどは、メディアにフラッシュされることなくメモリに残ります。Most of the file's data remains in memory without being flushed to the media because the file will soon be deleted.
戻り値Return Value
正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。Nonzero if successful; otherwise 0. 拡張されたエラー情報を取得するには、Win32 関数 GetLastErrorを呼び出します。To get extended error information, call the Win32 function GetLastError.
解説Remarks
を呼び出す前に、 FindNextFile を少なくとも1回呼び出す必要があり MatchesMask
ます。You must call FindNextFile at least once before calling MatchesMask
.
例Example
// This code fragment shows all of the files in the root directory
// of drive C: which have either the hidden attribute or the system
// attribute, or both.
CFileFind finder;
BOOL bWorking = finder.FindFile(_T("C:\\*.*"));
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.MatchesMask(FILE_ATTRIBUTE_HIDDEN |
FILE_ATTRIBUTE_SYSTEM))
{
_tprintf_s(_T("%s\n"), (LPCTSTR) finder.GetFileName());
}
}
関連項目See also
CObject クラスCObject Class
階層図Hierarchy Chart
CFtpFileFind クラスCFtpFileFind Class
CGopherFileFind クラスCGopherFileFind Class
CInternetFile クラスCInternetFile Class
CGopherFile クラスCGopherFile Class
CHttpFile クラスCHttpFile Class