Thread: Help on renaming files using a C program

  1. #16
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by Salem
    How about invoking your program with
    myrenamer.exe 0*.bnf

    Code:
    int main ( int argv, char *argv[] ) {
      for ( i = 1 ; i < argc ; i++ ) {
        // put the code Dave posted, using argv[i] as the input string
      }
    }
    I think the OP is using Windows. The standard Windows command interpreter does not expand wildcards in program arguments.

    However, Windows Explorer will provide a list of files in argv if they are drag and dropped on your program, so this might be a way to avoid manually enumerating files on Windows.
    Last edited by anonytmouse; 08-02-2006 at 06:36 PM.

  2. #17
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well I would hope not. Why should it change the argument you pass it? You've typed "0*.bnf", why should it change that to a crap load of files (assuming you have a crapload, and not the standard 'Metric Tonne', not to be confused with the ever popular ........pile)?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #18
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    I'm surprised nobody mentioned this yet

    Code:
    int main ( int argv, char *argv[] ) {
      for ( i = 1 ; i < argc ; i++ ) {
        // put the code Dave posted, using argv[i] as the input string
      }
    }
    [fear]Sorry Salem, please don't hurt me, I'm only young![/fear]
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  4. #19
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    Quote Originally Posted by Salem
    > how come i dont see a single rename() function in the code?
    Because we're not here to spoon feed you the complete answer.

    You're expected to take what has been given to you and adapt it to your own circumstances, and do some reading to fill in the blanks.

    > Then use the rename() function to rename the old file to the new file.
    I told you about the rename function, what more do you want?
    Basically, all you had to do is look up the function to work out whether it was
    rename("old","new") or rename("new","old").
    If that's too much, try something else in life.
    ahhhh.. my apologies master Salem... since im a newbie programmer here, i thought maybe that the code had another method of renaming the file, other than the rename function...

    anyways, i think i understand the code now.. only one more problem though: how do i complete the code such that i would only specify a path/directory and then then program would handle opening the first file (if it sees one), traverse through the directory, renaming files that start with a number, skipping those not, and ends when i can no longer open any file..

    basically, how do i set the program to open a file it encounters (without requiring input for filenames, then rename it, then move on to next file, then terminate when it doesnt find anymore files.)

    sorry for being such a bugger u guys... =D

  5. #20
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Look at the the opendir() and readdir() functions.
    If you understand what you're doing, you're not learning anything.

  6. #21
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > i would only specify a path/directory and then then program ...

    Remember this post?
    FAQ > How do I... (Level 3) > Accessing a directory and all the files within it

    It's deja-FAQ all over again.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #22
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    ahhhh okei.. thanks guys... i guess i'll hafta study them on my own then huh... =D

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get program to copy itself into program files, then start on startup.
    By guitarist809 in forum Windows Programming
    Replies: 6
    Last Post: 03-03-2008, 09:42 AM
  2. Replies: 5
    Last Post: 02-11-2008, 01:36 AM
  3. Multiple source files for one program
    By gflores in forum C++ Programming
    Replies: 3
    Last Post: 08-15-2004, 02:32 AM
  4. my program wont read my text files in??
    By Neildadon in forum C++ Programming
    Replies: 2
    Last Post: 12-15-2002, 10:08 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM