did work. Which qoute did you use in 1st proposal: Copying ‘ gives me strange results. I changed it to ’ but also there no success.Can you comprehend my problem (with any directory of your choice)?
I could solve it with a script but a single command would be more vonvenient for integration into my batch system.
Many thanks: It runs without error! But now I have a followup question: My expectation was that the DOS-ERRORLEVEL would reprepresent the result of the statement (in my case : 5 for 5 files found). Instead ERRORLEVEL is 0 (zero).
Any way to get the result into the calling DOS batch (except using a script or writing (OUT) it into a textfile)?
Michael
First of all: There is no “DOS” anymore for more than 20 years! It is the “command prompt”, “CMD” or maybe “batch file” … but no “DOS”.
The general recommendation is: “Do not use ancient batch files anymore!” PowerShell is mor than capable to replace any possible batch file because it is way more advanced and powerful.
Your expectation is wrong. The “ERRORLEVEL” is genereted by the PowerShell process itself - not the script running in it. And there are two defaults. “0” for success and “1” for failure. You can advice PowerShell to return a diffent numeric error level by using the keyword Exit followed by the number you want.
Again - don’t use batch files anymore. Migrate them to native PowerShell.
Sorry for historic wording on DOS / batch etc. , but the envíronment semmed to be clear.
Migration: My batch system consists of about 2.200 KB of code. Migration would be a too big effort doing it at once. So my concept is doing it step by step.
Obviously I cannot include an exitcode into a command as above?
I’d expect it to shrink actually when migrated to PowerShell because of the advanced language features. And you’ll very likely find easier help for PowerShell.
I never had to get familiar with CMD/Batch in depth and I refuse to start with it now. Especially when it comes to loops and variables I think the syntax of CMD/Batch is just atrocious and I don’t like to think about it. Sorry.