views:

208

answers:

4

I am making a console application where I drop files onto the .exe from Explorer and it will move them to the appropriate folder based on rules I have set in the logic of the program.

The program works great, but when I select more than 25 files and drop them on my .exe I get an error:

Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.

If I only drop 24 files from the same set it works fine.

What am I doing wrong?

+2  A: 

Is the number of files causing the maximum length of the command line (and thus arguments) to be exceeded, which causes this error?

Rob
could bethats what im asking i guess
Crash893
@Rob - Your answer should have been a comment and not posted as answer. -1
ichiban
@divo - my reasoning: for a Newb that would have been acceptable, but for a veteran of the site to post a question that restates what the OP is already saying is not helpful.
ichiban
+1, so the answer was phrased as a question, however "causing the maximum length of the command line (and thus arguments) to be exceeded" was correct
Patrick McDonald
@Ichiban - err, no. I'll phrase my answers in any way I please. Giving a -1 because you don't like the way an answer is phrased is a little bit counterproductive to the aims of the site don't you think?
Rob
+8  A: 

Depending on your platform, you may be running into the maximum command line length. See Here for more info.

"On computers running Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters. On computers running Microsoft Windows 2000 or Windows NT 4.0, the maximum length of the string that you can use at the command prompt is 2047 characters."

Adam Markowitz
you beat me to it.now i guess the question is how can i get around it?
Crash893
This seems right to me. The reason you'd get a "Cannot find specified path etc" error is that it's trying to hunt down a partial file name. I see you tagged this C#. Try setting a breakpoint on the loop that tests files, conditionally to only trigger on the 24th or 25th iteration (or only on 25.txt, which is the 25th file you put in). Then look and see if you are getting a partial file name.
CodexArcanum
Double posting it seems. How to get around? Easy, piping. I'm not sure exactly how in CMD to do it, but you can do something like this in Powershell or *nix shells:dir | MyProgram That will list the contents of a directory, and then feed each item one at a time into MyProgram (which is, of course, your app).
CodexArcanum
I made a new updated question to ask what i really wnatedhttp://stackoverflow.com/questions/916794/what-is-the-sleakest-way-to-proccess-multiple-files
Crash893
+1  A: 

On computers running Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters. On computers running Microsoft Windows 2000 or Windows NT 4.0, the maximum length of the string that you can use at the command prompt is 2047 characters.

I tested it out and yep thats what im running into.

can anyone think of a way around this?

Crash893
A simple way around this would be to use a config file.
0xA3
Use comments or edit your question. This is not a forum.
Geoffrey Chetwood
@Crash893 - This should be an edit to your original question or better yet you could accept the answer and post a whole new question for this.
ichiban
@Divo - could you explain a little better please@Rich B = i think it pertains to the original line of the question @Whoever - I think someone has a little to ichy of a finger on their -1 gun.
Crash893
@Divo: This is not fine. It is not an answer.
Geoffrey Chetwood
@ Rich B + Divo could you two take it out side please
Crash893
I agree that this would be better as part of the question since it really only seems to clarify what the problem is, not solve it.
Bill the Lizard
+1  A: 

To answer the follow-up, a little more info about the purpose of the app might be required, but if possible you might change your command line args to accept a folder path and a pattern to match all the necessary files you want to route. Or change it to a GUI app with a grid that you can drag-drop into.

TheMissingLINQ
I was hoping to avoid that. the eloquent part (or at least i thought it was) of my program is that it doesn't need to run in the background it would start up with the arguments given then die when it was done. If i created a winform that i could simply drag files on to the winform i could get around it but it adds a step to a proccess -- the other idea was to have a folder with a systemfilewatcher but that would have to run in the background
Crash893