Click here to Skip to main content
15,887,444 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I have an array of strings which contains the file names and I call a function in a loop.

char myFiles [20][50];

for(i=0;i<20;i++)
 myFunc( myFiles[i]);


The challenge I am facing is that, I have to store all the files in a directory, say "input" folder.... and then call
myFunc( myFiles[i]);
which I am unable to do.

I used mkdir("input"); to create a directory and moves all my files into it also using
system("move *.txt input");


But now if I give that path in my function it has to be hardcoded which eventually cannot be run in a loop.
ie
for(i=0;i<20;i++)
myFunc("C:\\input\\myFiles[i]"); //which is not possible....


I am using eclipse IDE.


Thanks in advance,
Faez
Posted

You can follow following steps in your loop

char FileName[1024] = {0};
for(i = 0; i<20;i++)
{
	sprintf(FileName,"C:\\input\\myFiles[%d]",i);
	myFunc(FileName);	
}


In this way you are able to create you file name dynamically.
 
Share this answer
 
Comments
Faez Shingeri 27-Feb-12 7:23am    
This does not work.. I get a Win32 exception handling error
Moreover when I print "Filename" it prints as
C:\\input\\myFiles[0]
C:\\input\\myFiles[1] and so on...
Jochen Arndt 27-Feb-12 7:29am    
I think his intention was something like
sprintf(FileName,"C:\\input\\%s", myFiles[i]);
I used the following

system("copy /input/*.txt  ");
/* After manipulations with the file..*/

system("del *.txt);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900