| | |
Want to execute a command on all files recursively
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 15
Reputation:
Solved Threads: 0
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 ?
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 ?
This sounds too much like something to do with spyware, viruses, or other generally annoying things. Can you explain what you are doing first?
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.
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.
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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
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.
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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.
•
•
Join Date: Feb 2009
Posts: 15
Reputation:
Solved Threads: 0
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.
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.
![]() |
Similar Threads
- Virus scanner file(php) cannot be executed (PHP)
- Quick Reference for Linux Commands (Getting Started and Choosing a Distro)
Other Threads in the C# Forum
- Previous Thread: Regular expression required
- Next Thread: property and array
| Thread Tools | Search this Thread |
.net access algorithm array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ grantorrevokepermissionthroughc#.net httpwebrequest image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop php picturebox pixelinversion post programming radians regex remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf wpfc# xml






