Thread: Opening all files in a directory

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    7

    Question Opening all files in a directory

    Hi,
    I want to write a programm that does this:
    1.Find the first file in the directory
    2.print its name into a input field
    3.rename the file

    Then the same procedure happens with the second file. The programm should rename all files in the directory.

    My questions are:
    1.How can I get a filename from the directory?
    2.How can I print a text into an input field(like scanf or gets)?

    I´m writing the program for linux.

    Thanks.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    How can I get a filename from the directory?
    opendir, readdir, and closedir. See the FAQ.

    Code:
    gets
    Not good. Don't use gets.

    print its name into a input field
    That's silly. You can't do that. Do you mean just print the name?

    The programm should rename all files in the directory.
    To what?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    7
    I meant fgets, sorry. My plan is this: I got a lot of files in a directory and some of the file names have mistakes(like a character should be lower case). I want the program to show me the name of the file and if it´s correct, i´ll simply press enter and everything stays the same. If the filename is wrong I want to simply change the filename in the textfield and press enter and then it should change the name. I now know how to get the filename thanks.
    Last edited by TKMan; 11-11-2005 at 01:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can i check a directory for certain files?
    By patrioticpar883 in forum C++ Programming
    Replies: 13
    Last Post: 02-01-2008, 05:27 PM
  2. Listing specific files in a directory
    By knirirr in forum C Programming
    Replies: 14
    Last Post: 01-29-2008, 05:42 AM
  3. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  4. opening files sequentially
    By barneygumble742 in forum C++ Programming
    Replies: 9
    Last Post: 12-21-2006, 11:26 AM
  5. Opening files - Giving options?
    By wwwGazUKcom in forum C++ Programming
    Replies: 3
    Last Post: 09-18-2001, 07:06 AM