CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 1999
    Location
    England
    Posts
    6

    Searching for a specific directory??

    I am writing a small program that deals with the uninstallation of a application. I need to find specific directories that the files have been installed to, such as the windows directory, the system dirctory and the applications own directory. As these directories can be situated in different places on different machines it is necessary for me to search for these!! Could anybody tell me a way in which this could be possible??

    Thanks in advance

    Paul


  2. #2
    Guest

    Re: Searching for a specific directory??

    hi,

    if your are looking for windows directory (or windows\system) there is one dos variable : windir = c:\Windows ore whatever is your windows directory.

    In a dos shell, type set to see all the environment variables.

    I think you can use theses variables in VC to find windows directory and so windows\system

    hope this helps.


  3. #3
    Join Date
    Jul 1999
    Location
    Israel
    Posts
    1,793

    Re: Searching for a specific directory??

    Hi there.
    check this functions:

    char buff[MAX_PATH];
    GetSystemDirectory(buff,MAX_PATH);//this will give you the WinDirectory\system. winDirectory is the dir that the user choose for installing windows

    //gor getting the actual windows directory use
    char buff[MAX_PATH];
    GetWindowsDirectory(buff,MAX_PATH);




    as MAX_PATH is the size of the buffer that you defined.

    HTH
    kishk91


    [email protected]
    http://www.path.co.il
    ICQ: 13610258

  4. #4
    Join Date
    Sep 1999
    Location
    England
    Posts
    6

    Re: Searching for a specific directory??

    Thankyou for the help!!

    But, I still have the problem of finding the folder for my application. eg. The application folder is Game1, how could I find this from the root directory?

    Any suggestions??

    Thanks again

    Paul


  5. #5
    Join Date
    Jul 1999
    Location
    Israel
    Posts
    1,793

    Re: Searching for a specific directory??

    Hi chekc this code. someone here gave it to me
    i never actually had chance to check it but ill be glad to hear that its works..


    void Recurse(CString strDirName)
    {
    WIN32_FIND_DATA wfd;
    HANDLE hFind;
    CString strDirText; // This will contain your Dir Name (and PATH)
    CString strFileText; // This will contain your File Name (and PATH)
    char Buf[254];
    char DirBuf[254];
    char FileBuf[254];
    CString ShareName, Dir, FName, Ext;
    ULONGLONG uhDirSize; // These only need to be DWORDs I did this for CRC Checking
    ULONGLONG uhFileSize;// These only need to be DWORDs I did this for CRC Checking
    // this is just if I decide to Abort in the middle of a search
    // volatile BOOL m_bAbort;
    if (!m_bAbort) {
    uhDirSize = 0;
    // Check if the last char is a back-slash
    // (If not, put it there)
    if (strDirName.Right(1) != "\\")
    strDirName += _T("\\");
    // set the variable and add an astrix for
    // the beginning of the directory search.
    strText = strDirName + _T("*");

    // Iterate through dirs
    hFind = FindFirstFile(strText, &wfd);
    if (hFind != INVALID_HANDLE_VALUE) {
    do {
    if (m_bAbort) return;

    // Check if "." or "..", if not...
    // Check if its a directory.
    if ((strcmp(wfd.cFileName,_T("."))) && (strcmp(wfd.cFileName,_T(".."))) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
    // Set to the directory found.
    strDirText = strDirName + wfd.cFileName;

    if (m_bAbort)
    return;
    // If we need to recursively search, then do so.
    if (m_Recurse) {
    // Call this function again.
    Recurse(strDirText);
    }
    }
    } while (FindNextFile(hFind, &wfd));
    // This is a MUST
    FindClose(hFind);
    }

    // Iterate through files
    //
    // set the variable and add an astrix-dot-astrix "*.*"
    // for the beginning of the file search.
    strText = strDirName + _T("*.*");//strMask;
    hFind = FindFirstFile(strText, &wfd);
    if (hFind != INVALID_HANDLE_VALUE) {
    do {
    if (m_bAbort)
    return;
    // If NOT a directory...
    if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
    // Set to the file found.
    strFileText = strDirName + wfd.cFileName;
    strFileText.MakeUpper();
    // Get the size of the file.
    uhFileSize = (wfd.nFileSizeHigh << 32) + wfd.nFileSizeLow;
    uhDirSize += uhFileSize;
    }
    } while (FindNextFile(hFind, &wfd));
    // This is a MUST
    FindClose(hFind);
    }
    } // end abort
    }




    let me know if its works ok ?

    regards
    kishk91

    [email protected]
    http://www.path.co.il
    ICQ: 13610258

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured