New File

E

EngineerGeek

Alright...I'm still new to programming, but I am already writing a
program for an internet business. Is there a way for me to make a new
folder with the name of the folder variable to a name read from a text
document and write a new text document inside of that folder? So
basically the name of the folder being made in the program would change
according to the name it recieved from each text file. I hope that all
made sense... Im pretty stuck with this and hope someone out there can
help me.
-Thanks
 
S

SM Ryan

# Alright...I'm still new to programming, but I am already writing a
# program for an internet business. Is there a way for me to make a new
# folder with the name of the folder variable to a name read from a text
# document and write a new text document inside of that folder? So
# basically the name of the folder being made in the program would change
# according to the name it recieved from each text file. I hope that all
# made sense... Im pretty stuck with this and hope someone out there can
# help me.

Usually any command you can enter at a command line interface, you can
do with the system() function. For example, on Unix, you can do
something like
char *dir = ... ;
char F[] = "mkdir -m 0755 '%s'";
char *f = malloc(strlen(dir)+sizeof F);
sprintf(f,F,dir);
int ec = system(f);
free(f);

Your system probably provides additional interfaces beyond ANSI C. For
example, again on Unix, you can do
char *dir = ... ;
int ec = mkdir(dir,0755);

With due care you can include the interfaces for a variety systems in
your code.
 
M

Martin Ambuhl

EngineerGeek said:
Alright...I'm still new to programming, but I am already writing a
program for an internet business. Is there a way for me to make a new
folder with the name of the folder variable to a name read from a text
document and write a new text document inside of that folder? So
basically the name of the folder being made in the program would change
according to the name it recieved from each text file. I hope that all
made sense... Im pretty stuck with this and hope someone out there can
help me.

C does address file systems, since they are completely OS-specific. In
situations where the directory (or "folder" in baby-talk) exists
already, the actual name of the file is built of a path to the
directory, a separator, and then the "local" name of the file. Such
names can be built easily with standard C funtionality and used to open
a new file. If, however, you need to create a new directory, you will
need to use the functionality your OS provides for what is, after all,
OS-specific. If your documentation is inadequate (or, more likely, you
don't know how to use it), ask in a newsgroup for your OS. Such details
are not part of the C language.
 
M

Martin Ambuhl

Martin said:
C does address file systems, since they are completely OS-specific.

That should have been "C does *not* address file systems, since they are
completely OS-specific."
 
G

Gordon Burditt

Alright...I'm still new to programming, but I am already writing a
program for an internet business. Is there a way for me to make a new
folder with the name of the folder variable to a name read from a text
document and write a new text document inside of that folder? So

Functions such as fopen() accept string arguments for the name of
a file. That name need not be a constant. You can compute it using
whatever method you like. sprintf() is commonly used to construct
filenames from pieces, but there's no rule you have to use it.

C does not have support for folders, nor foulders. If your system
has a way of creating them, such as mkdir(), or with a call to
system(), you might use that. It is implementation-specific as to
whether mkdir() creates a directory, a folder, or a foulder, if
mkdir() exists at all.
basically the name of the folder being made in the program would change
according to the name it recieved from each text file. I hope that all
made sense... Im pretty stuck with this and hope someone out there can
help me.

Gordon L. Burditt
 
S

SM Ryan

(e-mail address removed) (Gordon Burditt) wrote:

# C does not have support for folders, nor foulders. If your system

I do it in C all the time.

Perhaps you meant ANSI C. Programmers know the importance of precision
in specifications, as compared to programmer wannabes.
 
K

Kenny McCormack

(e-mail address removed) (Gordon Burditt) wrote:

# C does not have support for folders, nor foulders. If your system

I do it in C all the time.

No, you don't. You just think you do. See below.
Perhaps you meant ANSI C. Programmers know the importance of precision
in specifications, as compared to programmer wannabes.

In this NG, "C" means "ANSI C". I thought you understood that by now.

P.S. Where did the reference to "foulders" come from? I must have missed
that in the original post.

P.P.S. Gotta love Martin's turn-of-phrase: "(Or, in baby-talk, folders)"
Defintely dead on! Well done, sir!
 
S

SM Ryan

(e-mail address removed) (Kenny McCormack) wrote:
# In article <[email protected]>,
# >[email protected] (Gordon Burditt) wrote:
# >
# ># C does not have support for folders, nor foulders. If your system
# >
# >I do it in C all the time.
#
# No, you don't. You just think you do. See below.

Yes, I do.

# >Perhaps you meant ANSI C. Programmers know the importance of precision
# >in specifications, as compared to programmer wannabes.
#
# In this NG, "C" means "ANSI C". I thought you understood that by now.

I thought you realized only usenet kooks try to moderate an
unmoderated newsfroup. Also ANSI/ISO don't have a trademark on "C",
so they cannot claim (nor do they even try) to be The "C".

Again, real programmers try to be aware of their assumptions. It's the
wannabe that plow through in blithe ignorance of what is going on around
them.

# P.P.S. Gotta love Martin's turn-of-phrase: "(Or, in baby-talk, folders)"
# Defintely dead on! Well done, sir!

Yeah, always laugh at the new guy. Didn't you outgrow that kind of
juvenile nonsense after leaving high school?
 
P

Penguin_X

EngineerGeek said:
Alright...I'm still new to programming, but I am already writing a
program for an internet business. Is there a way for me to make a new
folder with the name of the folder variable to a name read from a text
document and write a new text document inside of that folder? So
basically the name of the folder being made in the program would change
according to the name it recieved from each text file. I hope that all
made sense... Im pretty stuck with this and hope someone out there can
help me.
-Thanks
Hi EngineerGeek.

You can use standart library as fstream(C++), but I don't know in C.
Working with directories and files in C isn't without difficulties with
standart stuff. Perhaps, you will need extra libs to do your project.

For myself, i'm using Perl in these kinds of problems. Perl has a very
extensible and easy-to-use syntax. String manipulation and working with
files or directories is a kid game ! Somebody talked me about a perl lib
for C. So, you will be able to add Perl features into your C code.

Best regards,

Penguin_X
 
P

Penguin_X

EngineerGeek said:
Alright...I'm still new to programming, but I am already writing a
program for an internet business. Is there a way for me to make a new
folder with the name of the folder variable to a name read from a text
document and write a new text document inside of that folder? So
basically the name of the folder being made in the program would change
according to the name it recieved from each text file. I hope that all
made sense... Im pretty stuck with this and hope someone out there can
help me.
-Thanks
remove "best regards" and replace by "truly", i can't say that in
english huhuh(sorry for my poor english man)
 
K

Kenny McCormack

(e-mail address removed) (Kenny McCormack) wrote:
# In article <[email protected]>,
# >[email protected] (Gordon Burditt) wrote:
# >
# ># C does not have support for folders, nor foulders. If your system
# >
# >I do it in C all the time.
#
# No, you don't. You just think you do. See below.

Yes, I do.

# >Perhaps you meant ANSI C. Programmers know the importance of precision
# >in specifications, as compared to programmer wannabes.
#
# In this NG, "C" means "ANSI C". I thought you understood that by now.

You might want to check out "irony" in the dictionary.
(or online at m-w.com)
I thought you realized only usenet kooks try to moderate an
unmoderated newsfroup. Also ANSI/ISO don't have a trademark on "C",
so they cannot claim (nor do they even try) to be The "C".

The idea that *I* am policing this ng is beyond funny.
Just ask any of the real regulars around here...
Again, real programmers try to be aware of their assumptions. It's the
wannabe that plow through in blithe ignorance of what is going on around
them.

Couldn't agree more, but that's not the religion practiced here.
 
E

EngineerGeek

Thank you all for correcting me as much as possible...and degrading my
experience. Programming is not specifically my area of focus...
electrical engineering is so I'll try to get some of that straight for
ya.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,166
Messages
2,570,901
Members
47,442
Latest member
KevinLocki

Latest Threads

Top