[SOLVED] How to check whether inserted SD Card is write protected or not in Qt?



  • Hi friends I am working on an application where I should check the file system of the SD card and also I need to check whether the SD card inserted is write protected or not. I was successful in getting the file system details as follows:

    @TCHAR volumeName[MAX_PATH + 1] = { 0 };
    TCHAR fileSystemName[MAX_PATH + 1] = { 0 };
    DWORD serialNumber = 0;
    DWORD maxComponentLen = 0;
    DWORD fileSystemFlags = 0;
    
    LPCWSTR path = deviceData->m_strPath.utf16(); // deviceData gives me the path of the SD Card
    
    // Get the file system details
    if (GetVolumeInformation(
                             path,
                             volumeName,
                             ARRAYSIZE(volumeName),
                             &serialNumber,
                             &maxComponentLen,
                             &fileSystemFlags,
                             fileSystemName,
                             ARRAYSIZE(fileSystemName)))
                {
                    newData.strFileSystem = QString::fromUtf16(fileSystemName);                
                }
    
     m_SDInfoList.append(newData); // m_SDInfoList is QList@
    

    With this approach I get to know whether the file system is FAT32 or NTFS. Now I want to achieve the write protected details. Is their a Qt API that can gimme whether the inserted SD Card is write protected or not??? Please help :)

    Update:

    This is what I did using QFileInfo:

    @QFileInfo fileInfo(deviceData->m_strPath);

    if(!fileInfo.isWritable())
    {
    newData.strStatus = "WriteProtect Enabled";
    }
    else
    {
    newData.strStatus = "WriteProtect Disabled";
    }@

    It always ends up giving me WriteProtect Disable even though I have set the write protected permission. Am I missing something??



  • I have updated the question. Please check :)


  • Moderators

    There are classes in QtSensors and in some external projects (QDriveInfo?) that would help you here. I think it returns false for ::isWritable() because you do not point to a valid file path (it's the path to the device, but not a potential file).



  • Thanks sierdzio :)

    [quote author="sierdzio" date="1366697003"]There are classes in QtSensors and in some external projects (QDriveInfo?) that would help you here. I think it returns false for ::isWritable() because you do not point to a valid file path (it's the path to the device, but not a potential file).[/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.