Re: Directory listing

From: Alad (imzhanghao_at_tom.com)
Date: 12/24/03


Date: Wed, 24 Dec 2003 09:32:59 +0800


// FROM MSDN LIBRARYWIN32_FIND_DATA FileData;
HANDLE hSearch;
DWORD dwAttrs;
char szDirPath[] = "c:\\TEXTRO\\";
char szNewPath[MAX_PATH];
char szHome[MAX_PATH];

BOOL fFinished = FALSE;

// Create a new directory.

if (!CreateDirectory(szDirPath, NULL))
{
    ErrorHandler("Couldn't create new directory.");
}

// Start searching for .TXT files in the current directory.

hSearch = FindFirstFile("*.txt", &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
    ErrorHandler("No .TXT files found.");
}

// Copy each .TXT file to the new directory
// and change it to read only, if not already.

while (!fFinished)
{
    lstrcpy(szNewPath, szDirPath);
    lstrcat(szNewPath, FileData.cFileName);
    if (CopyFile(FileData.cFileName, szNewPath, FALSE))
    {
        dwAttrs = GetFileAttributes(FileData.cFileName);
        if (!(dwAttrs & FILE_ATTRIBUTE_READONLY))
        {
            SetFileAttributes(szNewPath,
                dwAttrs | FILE_ATTRIBUTE_READONLY);
        }
    }
    else
    {
        ErrorHandler("Couldn't copy file.");
    }

    if (!FindNextFile(hSearch, &FileData))
    {
        if (GetLastError() == ERROR_NO_MORE_FILES)
        {
            MessageBox(hwnd, "No more .TXT files.",
                "Search completed.", MB_OK);
            fFinished = TRUE;
        }
        else
        {
            ErrorHandler("Couldn't find next file.");
        }
    }
}

// Close the search handle.

if (!FindClose(hSearch))
{
    ErrorHandler("Couldn't close search handle.");
} "Andreas Iwanowski" <aimk@onlinehome.de> дÈëÓʼþ
news:bsab2o$vv0$1@online.de...
> Hello.
> Is there a function in the Win32 API that returns a list of
files/subfolders
> in a specific folder ?
>
>
>



Relevant Pages

  • Re: Finding substring in character array
    ... It works with a character array instead. ... is that there's no way to make one without already having all the characters in an array which then gets copied into the string. ... whereas you could fill all 1 MB with a char[]. ... If he insists on searching a char, i would suggest he reads up on the Boyer-Moore string searching algorithm. ...
    (comp.lang.java.programmer)
  • Extracting text from a declared string
    ... Ok...I've been searching and searching but I haven't been able to figure a ... I have a resultset that has 213 char. ... I know the exact field sizes they ... I want to extract that and keep going throught the text till the end. ...
    (microsoft.public.access.formscoding)
  • Re: Input file *.txt to dialog box
    ... Here's how you search for a complete string. ... are searching for in a char array. ... current character in the string. ...
    (microsoft.public.vc.mfc)
  • Re: Over the Limit complaint :-(
    ... >I have been searching for a group where people would understand, ... My name is Charlene, ... Bless you for your attitude and what you live with and you are most welcome ... loved member of this newsgroup with the name of Char or maybe you would ...
    (alt.support.arthritis)
  • Re: vsprintf in std
    ... I have been searching in help but I found that was hard to search. ... What I looking for was the std counterpart of CRT vsprintf. ... Hello Ali, ... forrmat is char * ...
    (microsoft.public.vc.language)