Results 1 to 9 of 9

Thread: how to get the list of files without their extensions in a specified directory in Qt

  1. #1
    Join Date
    Feb 2013
    Location
    Banzart
    Posts
    54
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default how to get the list of files without their extensions in a specified directory in Qt

    i want to get all the files that are loacated in a specified directory but without their extensions at the end
    i did this :
    Qt Code:
    1. QDir myDir(mConfigDirectory);
    2.  
    3. filters << "*.ini";
    4. myDir.setNameFilters(filters);
    5. list = myDir.entryList ();
    6. qDebug()<<list;
    To copy to clipboard, switch view to plain text mode 
    but i want to separate the name from the extension and get only names
    Sliver_Twist

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to get the list of files without their extensions in a specified directory in

    So use the functions in QString to remove the extension for each file name in the list

  3. The following user says thank you to ChrisW67 for this useful post:

    sliverTwist (3rd April 2013)

  4. #3
    Join Date
    Feb 2013
    Location
    Banzart
    Posts
    54
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to get the list of files without their extensions in a specified directory in

    Quote Originally Posted by ChrisW67 View Post
    So use the functions in QString to remove the extension for each file name in the list
    How is that ? i mean what is the function that remove a file extension ???
    Sliver_Twist

  5. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get the list of files without their extensions in a specified directory in


  6. The following user says thank you to Lesiok for this useful post:

    sliverTwist (3rd April 2013)

  7. #5
    Join Date
    Feb 2013
    Location
    Banzart
    Posts
    54
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to get the list of files without their extensions in a specified directory in

    Quote Originally Posted by Lesiok View Post
    the problem that this methode gives you characters after a suffix not before it !
    Sliver_Twist

  8. #6
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to get the list of files without their extensions in a specified directory in

    use the truncate() method of QString

    Qt Code:
    1. QString fileName("myFile.new.txt");
    2. qDebug() << fileName; // myFile.new.txt
    3. fileName.truncate(fileName.lastIndexOf('.'));
    4. qDebug() << fileName; // myFile.new
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to alainstgt for this useful post:

    sliverTwist (3rd April 2013)

  10. #7
    Join Date
    Feb 2013
    Location
    Banzart
    Posts
    54
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to get the list of files without their extensions in a specified directory in

    Maybe that could help me but still need to truncate from qstringlist !
    Sliver_Twist

  11. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to get the list of files without their extensions in a specified directory in

    QFileInfo::completeBaseName() should have worked, but you can also try QFileInfo::baseName()
    Get the result list as QFileInfoList using QDir::entryInfoList() instead of entryList() and then build you result list from that or use the entry info list for processing and retrieve the base names right there.

    Cheers,
    _

  12. The following user says thank you to anda_skoa for this useful post:

    sliverTwist (3rd April 2013)

  13. #9
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get the list of files without their extensions in a specified directory in

    Quote Originally Posted by sliverTwist View Post
    the problem that this methode gives you characters after a suffix not before it !
    Are You sure ? This from doc : The complete base name consists of all characters in the file up to (but not including) the last '.' character. and example :
    Qt Code:
    1. QFileInfo fi("/tmp/archive.tar.gz");
    2. QString base = fi.completeBaseName(); // base = "archive.tar"
    To copy to clipboard, switch view to plain text mode 

  14. The following user says thank you to Lesiok for this useful post:

    sliverTwist (3rd April 2013)

Similar Threads

  1. List all XML files in a directory
    By ouekah in forum Newbie
    Replies: 4
    Last Post: 30th August 2015, 09:47
  2. Replies: 1
    Last Post: 27th December 2012, 07:01
  3. How to list the ftp directory in tree widget?
    By Gokulnathvc in forum Newbie
    Replies: 4
    Last Post: 18th October 2012, 06:08
  4. How to get a list of file names in a directory?
    By khanhsk in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2012, 03:34
  5. directory and files
    By rmagro in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2008, 14:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.