Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Portuguese
  4. Verificar se é ficheiro ou pasta

Verificar se é ficheiro ou pasta

Scheduled Pinned Locked Moved Portuguese
4 Posts 3 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pemoamsi
    wrote on last edited by
    #1

    Neste momento construi um código em que em que vou à base de dados buscar um texto (ex: c:\wamp\file.txt) e ele verifica se é um ficheiro ou uma pasta, e toma acções diferentes. Aqui reside um claro bug, para o caso do ficheiro não ter extensão (o meu plano foi verificar se existia o ponto). Existe alguma maneira mais acertada de fazer isto, ou seja, sem este bug?

    Eu pensei também usar o seguinte:

    QString mPath = "C:/wamp/easy/easy";
    if(!mDir.exists(mPath))
    

    e criei um ficheiro de teste sem extesão em c:/wamp/easy, com o nome easy, mas sem nenhuma pasta, e o interessante é que ele diz que a pasta já existe.

    Alguém?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rodrigocg
      wrote on last edited by
      #2

      A Classe QDir faz isso...

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TioRoy
        wrote on last edited by
        #3

        Use QFileInfo:

        @
        QString mPath = “C:\wamp\easy\easy”;
        //....
        QFileInfo info1( mPath );
        if ( info1.isDir() ) {
        //É pasta
        } else {
        //É ficheiro
        }
        @

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pemoamsi
          wrote on last edited by
          #4

          Era mesmo issoTioRoy, muito obrigado :)

          Por acaso tinha lido num manual o seguinte:

          @ foreach(QFileInfo mitm, mDir.entryInfoList())
          {
          qDebug() << mitm.absoluteFilePath();
          if(mitm.isDir())
          {
          qDebug() << "Dir: " << mitm.absoluteFilePath();
          }
          if(mitm.isFile())
          {
          qDebug() << "File: " << mitm.absoluteFilePath();
          }
          }@

          Mas infelizmente também não funcionou (não percebi o problema) simplesmente não imprimia o conteudo :\

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved