Page 1 of 1

how to supress directory too long messages

Posted: 16 May 2014 11:50
by sambasiva
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

Re: how to supress directory too long messages

Posted: 16 May 2014 12:25
by aGerman
Providing it's an error message you could prepend or append 2>nul to the line.

Code: Select all

2>nul dir /b /s /a-d %LOCAL_DOMAINS_DIR%\*.state

Regards
aGerman

Re: how to supress directory too long messages

Posted: 17 May 2014 11:35
by sambasiva
redirecting 2>nul and 1>nul didn't work for me.
Still I see those messages.

Re: how to supress directory too long messages

Posted: 17 May 2014 11:40
by foxidrive
Try it again:


Code: Select all

dir /b /s /a-d "%LOCAL_DOMAINS_DIR%\*.state" >nul 2>&1

Re: how to supress directory too long messages

Posted: 18 May 2014 09:51
by sambasiva
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

Re: how to supress directory too long messages

Posted: 18 May 2014 09:57
by foxidrive
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

Posted: 18 May 2014 10:35
by sambasiva
Yes, I tried it.
Those messages are still there, however the stdout is empty.

Thanks
SS

Re: how to supress directory too long messages

Posted: 18 May 2014 10:47
by foxidrive
Is the folder on a network drive?

Re: how to supress directory too long messages

Posted: 18 May 2014 21:46
by sambasiva
No. This folder exists on the local disk itself. However this is a shared directory.

Re: how to supress directory too long messages

Posted: 18 May 2014 22:54
by sambasiva
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')

Re: how to supress directory too long messages

Posted: 18 May 2014 23:35
by penpen
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")

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')
The order of (redirecting) operations may be important, too:

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
Output (Win xp 32 bit home):

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.

Re: how to supress directory too long messages

Posted: 19 May 2014 05:24
by foxidrive
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

Posted: 19 May 2014 05:47
by Aacini
You don't need the DIR command in order to process such files; you may do that directly with a FOR /R:

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

Posted: 20 May 2014 01:05
by sambasiva
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

Re: how to supress directory too long messages

Posted: 20 May 2014 09:47
by Aacini
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!