473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to create multiple files inside a folder in C?

Hi ALL,

I 'm using DevC++ for writing a C source code to create multiple files and folders under a directory.With the help of mkdir command i am able to get a bunch of 40 folders in the current working directory.I have given here my code.


Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.       char folderNames[40][3];
  4.       int i,fptr;
  5.       mode_t dir_mode = S_IRWXU;
  6.       char *temp_name;
  7.  
  8.       for (i = 0 ; i < 40; i++)
  9.       {
  10.            sprintf(folderNames[i],"%d",(i+1));
  11.       }
  12.  
  13.  
  14.       for(i=0;i<40;i++)
  15.       {
  16.        temp_name = folderNames[i];
  17.        fptr = mkdir(temp_name,dir_mode); 
  18.       }
  19.  
  20.       (fptr == 0)? goodbye():error_msg();     
  21.       fflush(stdin);
  22.       getchar();
  23. }
What do I struggle now is to get into each of the folders and create files?How can I change the program control from the present working directory into the desired folders?I tried with system("cd 1")..but its not working..It gives the place where the program resides.

Some one Plz help me..

Thanks,
Rama
May 17 '07 #1
1 5811
AdrianH
1,251 Expert 1GB
What do I struggle now is to get into each of the folders and create files?How can I change the program control from the present working directory into the desired folders?I tried with system("cd 1")..but its not working..It gives the place where the program resides.

Some one Plz help me..

Thanks,
Rama
The current working directory is just a state (of mind as it were) to any process. And because system spawns a process, only that process only knows what state it is in. The system command will just not cut it.

See this link for the info you seek.


Adrian
May 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Tom Weston | last post by:
Help I have 4 databases containing different data relating to safety, not written by me. It is not possible to merge the databases into one large data base. I would like to create a user interface...
5
by: Rothariger | last post by:
Hello.... i want to know if its posible to rename multiple files like windows does.. example: file zzzzzzz.doc file asdasd.doc file esfsefse.doc
7
by: Terry Holland | last post by:
I have just created my first asp.net application and I am ready to deploy. The solution consists of the following: A single asp.net assembly to be deployed to web server A number of vb.net...
2
by: rengask | last post by:
I got the code to find and replace within an open text file. ------------------ Private Sub cmdFile_Click() Dim strTemp As String txtFile = "" dlg.FileName = "*.*" dlg.ShowOpen ...
5
by: anupkossambe | last post by:
Hello guys, I'm working on a code in VB6.0 which involves copying all the files inside a folder to another folder. I have managed to do that but the problem arises when there are subfolders inside...
0
by: rohitkumar | last post by:
i have a database having records of no. of people. i have to create no. of HTML files depending upon the no. of rows retrieved from database. i m creating a single html file using ...
4
by: Alan Mailer | last post by:
Again, I'm new to VB.net and there is something I need help with: Like (I assume) many of us, over time I want to be able to create some VB.net classes that I might want to use in more than one...
1
by: larryawade | last post by:
I need the ability to automate the creation of 500 similar webpages for an educational site. Let’s say approximately 100 lessons with each lesson having 3-5 pages. I already have a program that...
1
by: coolheadash | last post by:
Hi all, I have a folder named "folder" having multiple files inside different nested folders. Many files under it have a certain text that i am looking for. Before this line, I have to add a line...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.