By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,654 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,654 IT Pros & Developers. It's quick & easy.

Working with files and directories on Windows

P: n/a
Problem 1: I need to access a set of files all with same name and all
in subdirectories of the directory I run the executable in.

Problem 2. I need to edit a file but want to create a .bak first.

Are these possible for a C beginner or do they require the sacrifice of
of a young virgin and buying books on the Win32 API.

Sep 29 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a

pkirk25 wrote:
Problem 1: I need to access a set of files all with same name and all
in subdirectories of the directory I run the executable in.
see the description of the "system()" function. You can call it as:

system( "dir /B dirname\*.dat >\tmp.tmp" );
... that will put all the filenames in \tmp.tmp. Youc an then fopen()
tmp.tmp and read the file names from it, then fopen those files.
Easy.
>
Problem 2. I need to edit a file but want to create a .bak first.
fopen() it for reading fopen the .bak for writing, and read and write
all the bytes from one to the other. then close the files.

Some programs do it more quickly by just renaming the file.

Sep 29 '06 #2

P: n/a
"Ancient_Hacker" <gr**@comcast.netwrites:
pkirk25 wrote:
>Problem 1: I need to access a set of files all with same name and all
in subdirectories of the directory I run the executable in.

see the description of the "system()" function. You can call it as:

system( "dir /B dirname\*.dat >\tmp.tmp" );

.. that will put all the filenames in \tmp.tmp. Youc an then fopen()
tmp.tmp and read the file names from it, then fopen those files.
Easy.
The language doesn't define a "\*" escape sequence. "\t" is a
horizontal tab character.

There's almost certainly a better system-specific way to do this, and
since the "dir" command is system-specific anyway, nothing is lost by
using a more efficient method. (You're also assuming that "\tmp.tmp"
is writable.)

Ask in a Windows-specific newsgroup.
>Problem 2. I need to edit a file but want to create a .bak first.

fopen() it for reading fopen the .bak for writing, and read and write
all the bytes from one to the other. then close the files.
Or use some system-specific command that copies the file.

Ask in a Windows-specific newsgroup.
Some programs do it more quickly by just renaming the file.
Yes, rename() is a standard C function.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 29 '06 #3

P: n/a

Keith Thompson wrote:
renaming the file.
>
Yes, rename() is a standard C function.
http://www.elook.org/programming/c/rename.html

I haven't learnt how to use it but it looks like the answer.

My little program is a mod of World of Warcraft which is Mac, Linux and
Windows. The system command works fine on Windows. Thats 97% of
potential users catered for.

Is system("do something please now!") just as easy on Mac and Linux?
I'd like to know before I ask someone to install WoW and give me shell
access.

Sep 29 '06 #4

P: n/a
"pkirk25" <pa*****@kirks.netwrites:
Keith Thompson wrote:
renaming the file.
>>
Yes, rename() is a standard C function.
http://www.elook.org/programming/c/rename.html

I haven't learnt how to use it but it looks like the answer.

My little program is a mod of World of Warcraft which is Mac, Linux and
Windows. The system command works fine on Windows. Thats 97% of
potential users catered for.

Is system("do something please now!") just as easy on Mac and Linux?
I'd like to know before I ask someone to install WoW and give me shell
access.
The system() function is standard. The argument to the system()
function is entirely system-specific.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 30 '06 #5

P: n/a
Many thanks

Sep 30 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.