Hi,
I guess in every beginners C-book it writes about how to declare a
filepointer fp and how to create a file (at least in mine)...... Like here:
FILE * fp;
fp = fopen("output_file.txt", "w");
if( fp == NULL)
{
printf("Error: File could not be opened\n");
return 1;
}
....
....
But now I would like to test if a given directory exists and if not, I
want to create it so I can put data-files in that sub-directory... How
to do that? And why is that I guess many text-books don't discuss how to
do this?
Best regards / Med venlig hilsen
Martin Jørgensen
--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk 9 10495
"Martin Jørgensen" writes: I guess in every beginners C-book it writes about how to declare a filepointer fp and how to create a file (at least in mine)...... Like here:
<snip>
But now I would like to test if a given directory exists and if not, I want to create it so I can put data-files in that sub-directory... How to do that? And why is that I guess many text-books don't discuss how to do this?
The base language has no provisions for directories. But each compiler has
some stuff extracted from the API for the associated OS in header files that
will make sense *after* you know which headers they are :-( . So post your
question on a group that discusses your platform.
Martin Jørgensen wrote: Hi,
I guess in every beginners C-book it writes about how to declare a filepointer fp and how to create a file (at least in mine)...... Like here:
FILE * fp; fp = fopen("output_file.txt", "w");
if( fp == NULL) { printf("Error: File could not be opened\n"); return 1; }
... ...
But now I would like to test if a given directory exists and if not, I want to create it so I can put data-files in that sub-directory... How to do that? And why is that I guess many text-books don't discuss how to do this?
You can't do it portably, so a textbook on standard C wouldn't discuss
it much. K&R discusses some directory stuff in its chapter on Unix.
Anyway, see the FAQ: http://c-faq.com/osdep/mkdir.html
-David
On Wed, 12 Apr 2006 15:49:06 +0200,
Martin Jørgensen <un*********@spam.jay.net> wrote
in Msg. <j3************@news.tdc.dk> But now I would like to test if a given directory exists and if not, I want to create it so I can put data-files in that sub-directory... How to do that? And why is that I guess many text-books don't discuss how to do this?
Because Standard C doesn't know what a "directory" is. FWIW, neither
does this newsgroup.
robert
On 2006-04-12, Martin Jørgensen <un*********@spam.jay.net> wrote: Hi,
I guess in every beginners C-book it writes about how to declare a filepointer fp and how to create a file (at least in mine)...... Like here:
FILE * fp; fp = fopen("output_file.txt", "w");
if( fp == NULL) { printf("Error: File could not be opened\n"); return 1; }
... ...
But now I would like to test if a given directory exists and if not, I want to create it so I can put data-files in that sub-directory... How to do that? And why is that I guess many text-books don't discuss how to do this?
Best regards / Med venlig hilsen Martin Jørgensen
It would depend on the compiler environment. In Gnu C you could
look up mkdir().
David Resnick wrote: Martin Jørgensen wrote:
-snip-
You can't do it portably, so a textbook on standard C wouldn't discuss it much. K&R discusses some directory stuff in its chapter on Unix. Anyway, see the FAQ:
http://c-faq.com/osdep/mkdir.html
Thanks a lot. That probably tells how to create the directory. And how
to see if the directory exists in the first place?
Best regards / Med venlig hilsen
Martin Jørgensen
--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
Martin Jørgensen opined: David Resnick wrote: Martin Jørgensen wrote: -snip-
You can't do it portably, so a textbook on standard C wouldn't discuss it much. K&R discusses some directory stuff in its chapter on Unix. Anyway, see the FAQ:
http://c-faq.com/osdep/mkdir.html
Thanks a lot. That probably tells how to create the directory. And how to see if the directory exists in the first place?
You have to ask in a group that discusses your OS/implementation. As
was mentioned elsethread, Standard C knows nothing about directories.
--
"I once witnessed a long-winded, month-long flamewar over the use of
mice vs. trackballs...It was very silly."
(By Matt Welsh)
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
Martin Jørgensen wrote: David Resnick wrote: Martin Jørgensen wrote: -snip-
You can't do it portably, so a textbook on standard C wouldn't discuss it much. K&R discusses some directory stuff in its chapter on Unix. Anyway, see the FAQ:
http://c-faq.com/osdep/mkdir.html
Thanks a lot. That probably tells how to create the directory. And how to see if the directory exists in the first place?
So as someone else said, this discussion doesn't really belong
in comp.lang.c. You may get some ideas here: http://c-faq.com/osdep/fileexists.html
Reading through the FAQ is quite educational, I recommend trying it
as you find time, there is much to learn there.
If you want details on how to do directory manipulation, asking in a
group
dedicated to your particular platform is the way to go. For example,
if you us *nix, asking in comp.unix.programmer is a good idea.
-David
Martin Jørgensen wrote: David Resnick wrote: You can't do it portably, so a textbook on standard C wouldn't discuss it much. K&R discusses some directory stuff in its chapter on Unix. Anyway, see the FAQ:
http://c-faq.com/osdep/mkdir.html
Thanks a lot. That probably tells how to create the directory. And how to see if the directory exists in the first place?
The first link I followed in the page linked to by David Resnick led me
to a new page, within the 'c-faq' site, with enough information to
learn how to check if a directory exists.
--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Pedro Graca opined: Martin Jørgensen wrote: David Resnick wrote: You can't do it portably, so a textbook on standard C wouldn't discuss it much. K&R discusses some directory stuff in its chapter on Unix. Anyway, see the FAQ:
http://c-faq.com/osdep/mkdir.html
Thanks a lot. That probably tells how to create the directory. And how to see if the directory exists in the first place?
The first link I followed in the page linked to by David Resnick led me to a new page, within the 'c-faq' site, with enough information to learn how to check if a directory exists.
Oh, but that's too difficult!
--
"Whip me. Beat me. Make me maintain AIX."
(By Stephan Zielinski)
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lawrence |
last post by:
Google can't find me a good example of how to use the "if exists"
syntax in MySql. Is it right that to use it this way:
INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk")
I want...
|
by: anon |
last post by:
I have been used to using DAO in the past, and then converted to ADO.
Now I am having to use VB.Net(2000) and ADO.NET and am experiencing
difficulties with the creation and population of an mdb....
|
by: ST |
last post by:
Hi,
I'm sort of in a rush here...I'm sort of new to vb.net and I'm trying to
write the syntax to check a sql table to see if the record already exists
based on firstname and lastname text fields...
|
by: jennifer1970 |
last post by:
I need to insert records into the table parSalesDetailModifier from
OLDparSalesDetailModifier where (1) those records DO NOT exit in
parSalesDetailModifier and (2) those records have a parent...
|
by: Alicia |
last post by:
Does anyone know why I am getting a "Syntax error in Create Table
statement". I am using Microsoft Access SQL View to enter it. Any
other problems I may run into?
CREATE TABLE weeks
(...
|
by: Research-13 |
last post by:
thank
|
by: Peter |
last post by:
Hello£¬everyone,
My program will collect a testing machine's data ,save the data and deal
with the data everyday. I want to use vb.net to create database, add and
delete tables or modify the...
|
by: olav78 |
last post by:
create database test if not exists. Someone know how to do this in postgreSQL?
|
by: etuncer |
last post by:
Hello All,
I have Access 2003, and am trying to build a database for my small
company. I want to be able to create a word document based on the data
entered through a form. the real question is...
|
by: Wolfgang Meister |
last post by:
I would like to append text to a file which might exist or not.
What is the easiest way to open or create it depending if it exists or not
and to set it into an "append" text mode?
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |