writing files to a specified folder

This is a discussion on writing files to a specified folder within the Windows Programming forums, part of the Platform Specific Boards category; how do i write files to a specified folder with fwrite and FILE's? i'm trying to copy one file from ...

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903

    writing files to a specified folder

    how do i write files to a specified folder with fwrite and FILE's?

    i'm trying to copy one file from the current directory to a folder like C:\test\

    and just do it one byte at a time (i'm doing this on purpose, so dont' flame me)

    but the thing is, it writes for a couple seconds, then it just crashes.....

    but if i try and just write to a plain file (test.txt) instead of the directory one (C:\test\test.txt) it works perfectly......

    any way to fix this? example code would be nice

    thanks in advance

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    ah, i found my problem, i have to create a folder first.......so, how do i do that?

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Why don't you show us your code? Make sure you're using "rb" and "wb" for binary IO.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    ok, i found a cool command off of msdn:

    BOOL CreateDirectory(
    LPCTSTR lpPathName,
    LPSECURITY_ATTRIBUTES lpSecurityAttributes
    );

    now, thing is, will this cause errors if the folder already exists?

    say i try and create a folder C:\Program Files\
    will it overwrite the Program Files folder? cuz that would suck, lol

    if it does, is there a way to test if a folder exists?

    -edit-
    ok, nevermind, it doesn't overwrite stuff *phew*.....i think i've ALMOST got it done....
    Last edited by jverkoey; 03-29-2003 at 10:09 PM.

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Why don't you test that yourself? Just create a folder in Explorer, and try to create it again with CreateDirectory.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    read above ^^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting List of files in particular folder
    By Bargi in forum C++ Programming
    Replies: 4
    Last Post: 05-10-2007, 04:00 AM
  2. get files in a folder and more
    By appleGuy in forum Windows Programming
    Replies: 3
    Last Post: 09-05-2006, 08:59 AM
  3. Problems writing some chars to files with fprintf
    By Nazgulled in forum C Programming
    Replies: 3
    Last Post: 04-18-2006, 06:00 PM
  4. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  5. Reading binary files and writing as text
    By thenrkst in forum C++ Programming
    Replies: 8
    Last Post: 03-13-2003, 09:47 PM

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