moving files in C

This is a discussion on moving files in C within the C Programming forums, part of the General Programming Boards category; Hi! Here's the problem. I have a batch file that moves files from one directory to another, using the "move" ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    4

    Question moving files in C

    Hi!
    Here's the problem.
    I have a batch file that moves files from one directory to another, using the "move" command.
    It works ok.

    But when I try to run it from a C program using the function "system("file.bat");", the move command doesn't work.

    Giving the error message: "invalid command or bad filename".

    The line on the batch file is simply:

    move c:\enc\hist\*.lst c:\enc\

    Thanks to all.

  2. #2
    Registered User
    Join Date
    Jun 2007
    Location
    Rome, NY
    Posts
    24
    I know next to nothing about programming in windows but I am guessing usuallly some sort of shell processes the wildcard character in the file name.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    4
    My program is supposed to run in DOS 6.

    Anyway, I only want to move all files from one directory to another.

    I believe that the problem is that when using the program, DOS doesn't recognize the "move" command. But recognizes others, like "DIR".

    This is strange.. any ideas?

    Thanks!

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    4
    Hey, instead of "move", used "copy" + "del" and it works.

    Thanks!

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Indeed, DOS doesn't have MOVE as a command, so you need to copy the file, then delete the original.

    --
    Mats

  6. #6
    Registered User
    Join Date
    Aug 2007
    Posts
    4
    But when I use the move command in the console or in the batch file, it works fine.
    It only has problems when I call the file from the program...

    Any idea of how I make it work using only C code?

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Are you mixing up real, authentic DOS with a DOS shell?

    If you want to move files using C, the method to do it depends if you're using DOS or Windows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 02:47 AM
  2. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. moving files
    By warney_out in forum C Programming
    Replies: 1
    Last Post: 08-23-2005, 08:06 AM
  5. Moving files/deleting files/ copying, etc
    By Nakeerb in forum C++ Programming
    Replies: 1
    Last Post: 10-11-2002, 05:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21