Want to execute a command on all files recursively

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2009
Posts: 15
Reputation: ppraj is an unknown quantity at this point 
Solved Threads: 0
ppraj ppraj is offline Offline
Newbie Poster

Want to execute a command on all files recursively

 
0
  #1
Feb 26th, 2009
Hi,

I have folder which is deep rooted (i.e many folders and files under it)
My requirement is to execute a command on each file on the above folder recursively and it should be fast.

My approach was to use to the Directory Get Files method to get the files in an array and loop though each file . While Looping through , I use the Process class something like this

Process P =new Process();
p.StartInfo.command="someexe";
p.StartInfo.arguments="<dynamically set by the filevalue in the loop everytime>";
p.Start();
p.WaitForExit();

The above method of execution takes an hour or so. Can I make the process faster using threads if so how ?
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Want to execute a command on all files recursively

 
0
  #2
Feb 26th, 2009
This sounds too much like something to do with spyware, viruses, or other generally annoying things. Can you explain what you are doing first?
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 15
Reputation: ppraj is an unknown quantity at this point 
Solved Threads: 0
ppraj ppraj is offline Offline
Newbie Poster

Re: Want to execute a command on all files recursively

 
0
  #3
Feb 26th, 2009
Hehe..
It is for labelling the source control (i.e Clearcase view that has the files loaded in it ). So trying to automate the same with a C# script which will call "cleartool.exe with a parameter of the path of the file to do the job. Hence the requirement to loop over all the files.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Want to execute a command on all files recursively

 
0
  #4
Feb 26th, 2009
Well for starters the p.WaitForExit() does just that... do you need to wait for the process to exit or are you just trying to stop 9999 processes from spawning at once? If so you could do something to only have N processes started by the application at once.

Threading is a possible solution but there is also overhead in creating and tearing down a thread, so you need to give us a little more information on this.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 15
Reputation: ppraj is an unknown quantity at this point 
Solved Threads: 0
ppraj ppraj is offline Offline
Newbie Poster

Re: Want to execute a command on all files recursively

 
0
  #5
Feb 27th, 2009
Let us not spawn 9999 processes of the cleartool.exe at once . That will make it really fast, bur atleast create a thread or two to the job run faster than the current one .
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Want to execute a command on all files recursively

 
0
  #6
Feb 27th, 2009
Best answer would be to recursively get a list of files, and pop the filename in a list

Then have a class which spawns say 5 threads max, and processes the file, so you dont thrash the heck out of everything but also achieve a realistic effect
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Want to execute a command on all files recursively

 
0
  #7
Feb 27th, 2009
ignore - dup
Last edited by LizR; Feb 27th, 2009 at 2:35 am.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 15
Reputation: ppraj is an unknown quantity at this point 
Solved Threads: 0
ppraj ppraj is offline Offline
Newbie Poster

Re: Want to execute a command on all files recursively

 
0
  #8
Feb 27th, 2009
Anybody ?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Want to execute a command on all files recursively

 
0
  #9
Feb 27th, 2009
ppraj, your last post has no point. You were the last to answer before me, I said something your response is clearly not in relation to that, so what was the point?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 15
Reputation: ppraj is an unknown quantity at this point 
Solved Threads: 0
ppraj ppraj is offline Offline
Newbie Poster

Re: Want to execute a command on all files recursively

 
0
  #10
Feb 28th, 2009
Yeah, I didn not see that..thanks
I'm aready loopinh though the files list, so the point it to spawn the prcoess across 5 threads. How can I do that ?
I also have a query like , when you spawn the process, how are you going to keep track of the files that are already prcessed by some other thread. To that I mean , we should not process a file in the list if the other thread has taken care of it.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC