how to supress directory too long messages
Moderator: DosItHelp
how to supress directory too long messages
Hi ,
I have a dir listing command to list all the *.state files recursively under a given directory.
dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state
However this dir command multiple times reports the following messages on the screen , which I wanted to supress/ignore.
The directory name "some directory name" is too long
I couldn't find any flag for dir command helpful.
Please help.
Thanks
SS
I have a dir listing command to list all the *.state files recursively under a given directory.
dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state
However this dir command multiple times reports the following messages on the screen , which I wanted to supress/ignore.
The directory name "some directory name" is too long
I couldn't find any flag for dir command helpful.
Please help.
Thanks
SS
Re: how to supress directory too long messages
Providing it's an error message you could prepend or append 2>nul to the line.
Regards
aGerman
Code: Select all
2>nul dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state
Regards
aGerman
Re: how to supress directory too long messages
redirecting 2>nul and 1>nul didn't work for me.
Still I see those messages.
Still I see those messages.
Re: how to supress directory too long messages
Hi foxidrive,
It didn't help.
Following is the code I have.
---------------------
FOR /F "delims=" %%a in ('dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state ^>nul 2^>^&1') do (
SET "statefile=%%a"
IF "!statefile:\servers\=!" neq "%%a" IF "!statefile:*\data\nodemanager\=!" equ "%%~NXa" (
FOR /f "tokens=*" %%i in ('type %%a') do SET state=%%i
echo STATUS: %%a , !state!
)
)
--------------------
Still I see those messages.
Note: Actually I need the stdout to printed. I have to supress only the messages "The directory name "some directory name" is too long".
Thanks
SS
It didn't help.
Following is the code I have.
---------------------
FOR /F "delims=" %%a in ('dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state ^>nul 2^>^&1') do (
SET "statefile=%%a"
IF "!statefile:\servers\=!" neq "%%a" IF "!statefile:*\data\nodemanager\=!" equ "%%~NXa" (
FOR /f "tokens=*" %%i in ('type %%a') do SET state=%%i
echo STATUS: %%a , !state!
)
)
--------------------
Still I see those messages.
Note: Actually I need the stdout to printed. I have to supress only the messages "The directory name "some directory name" is too long".
Thanks
SS
Re: how to supress directory too long messages
sambasiva wrote:Hi foxidrive,
It didn't help.
Note: Actually I need the stdout to printed. I have to supress only the messages "The directory name "some directory name" is too long".
Did you try it, or did you consider that it hides STDOUT too and didn't try it?
Re: how to supress directory too long messages
Yes, I tried it.
Those messages are still there, however the stdout is empty.
Thanks
SS
Those messages are still there, however the stdout is empty.
Thanks
SS
Re: how to supress directory too long messages
Is the folder on a network drive?
Re: how to supress directory too long messages
No. This folder exists on the local disk itself. However this is a shared directory.
Re: how to supress directory too long messages
Hi Foxidrive,
I am able to suppress those message by re-directing the stderr of the batch file to nul as below:
C:\>test.cmd C:\test\instance\domains 2>nul
test.cmd contains the below code
---------------------
FOR /F "delims=" %%a in ('dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state') do (
SET "statefile=%%a"
IF "!statefile:\servers\=!" neq "%%a" IF "!statefile:*\data\nodemanager\=!" equ "%%~NXa" (
FOR /f "tokens=*" %%i in ('type %%a') do SET state=%%i
echo STATUS: %%a , !state!
)
)
--------------------
Not sure why 2>nul is not working in the for loop with dir command
FOR /F "delims=" %%a in ('dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state ^>nul 2^>^&1')
I am able to suppress those message by re-directing the stderr of the batch file to nul as below:
C:\>test.cmd C:\test\instance\domains 2>nul
test.cmd contains the below code
---------------------
FOR /F "delims=" %%a in ('dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state') do (
SET "statefile=%%a"
IF "!statefile:\servers\=!" neq "%%a" IF "!statefile:*\data\nodemanager\=!" equ "%%~NXa" (
FOR /f "tokens=*" %%i in ('type %%a') do SET state=%%i
echo STATUS: %%a , !state!
)
)
--------------------
Not sure why 2>nul is not working in the for loop with dir command
FOR /F "delims=" %%a in ('dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state ^>nul 2^>^&1')
Re: how to supress directory too long messages
I'm not sure if your windows version is parsing the command other than my win xp home 32 bit,
Edited:
Wrong:
but this should have worked (if not, then you probably have used '... 2^>^&1 ^>nul' instead):
Correct:
the "^>nul 2^>^&1" part should supress the error messages, but supresses the stdout messages, too.
The "2>nul" part should have worked, if you would have escaped it ("2^>nul")
Output (Win xp 32 bit home):
penpen
Edits: Corrected my info... i watched only the "STDERR" message written to screen;
in addition you wrote that 2>nul does not work in for commands (was irritating to me).
Red old incorrect information, green new correct info.
Edited:
Wrong:
but this should have worked (if not, then you probably have used '... 2^>^&1 ^>nul' instead):
Correct:
the "^>nul 2^>^&1" part should supress the error messages, but supresses the stdout messages, too.
The "2>nul" part should have worked, if you would have escaped it ("2^>nul")
The order of (redirecting) operations may be important, too:Not sure why 2>nul is not working in the for loop with dir command
FOR /F "delims=" %%a in ('dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state ^>nul 2^>^&1')
Code: Select all
@echo off
cls
echo 1@
FOR /F "delims=" %%a in ('^(echo STDOUT ^& ^(echo STDERR ^>^&2^)^) ^>nul 2^>^&1') do echo @%%a
echo(
echo 2#
FOR /F "delims=" %%a in ('^(echo STDOUT ^& ^(echo STDERR ^>^&2^)^) 2^>^&1 ^>nul') do echo #%%a
echo(
echo 3+
FOR /F "delims=" %%a in ('^(echo STDOUT ^& ^(echo STDERR ^>^&2^)^) 2^>nul') do echo +%%a
echo(
echo 4-
FOR /F "delims=" %%a in ('^(echo STDOUT ^& ^(echo STDERR ^>^&2^)^) 2^>^&1') do echo -%%a
goto :eof
Code: Select all
1@
2#
#STDERR
3+
+STDOUT
4-
-STDOUT
-STDERR
penpen
Edits: Corrected my info... i watched only the "STDERR" message written to screen;
in addition you wrote that 2>nul does not work in for commands (was irritating to me).
Red old incorrect information, green new correct info.
Last edited by penpen on 19 May 2014 06:20, edited 2 times in total.
Re: how to supress directory too long messages
sambasiva wrote:FOR /F "delims=" %%a in ('dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state ^>nul 2^>^&1')
Did the code I suggest work when used outside a for loop, as posted from a cmd prompt?
I ask this because you didn't mention a for loop until now.
Re: how to supress directory too long messages
You don't need the DIR command in order to process such files; you may do that directly with a FOR /R:
Antonio
Code: Select all
FOR /R "%LOCAL_DOMAINS_DIR%" %%a in (*.state) do (
SET "statefile=%%a"
IF "!statefile:\servers\=!" neq "%%a" IF "!statefile:*\data\nodemanager\=!" equ "%%~NXa" (
FOR /f "tokens=*" %%i in ('type %%a') do SET state=%%i
echo STATUS: %%a , !state!
)
)
Antonio
Re: how to supress directory too long messages
Hi Antonio,
Thanks a lot. It worked like a charm for my requirement.
Now I don't see the long path messages.
One more question, does for /R can be used in similar fashion to distinguish the files and folders ?
Thanks
SS
Thanks a lot. It worked like a charm for my requirement.
Now I don't see the long path messages.
One more question, does for /R can be used in similar fashion to distinguish the files and folders ?
Thanks
SS
Re: how to supress directory too long messages
sambasiva wrote:One more question, does for /R can be used in similar fashion to distinguish the files and folders ?
Thanks
SS
No.
FOR /R only processes files and FOR /R /D only processes folders. If you want to process all folders and files below a starting folder, you may use this method:
Code: Select all
for /R "C:\Starting\Folder" /D %%d in (*) do (
echo Folder: %%d
for %%f in ("%%d\*.*") do echo File: %%f
)
Antonio
PS - Since your previous post about this matter, I never understood why you first mix all folder and file names, so you need later to "distinguish" between them!