how to supress directory too long messages

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sambasiva
Posts: 43
Joined: 02 Jun 2013 10:25

how to supress directory too long messages

#1 Post by sambasiva » 16 May 2014 11:50

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: how to supress directory too long messages

#2 Post by aGerman » 16 May 2014 12:25

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

sambasiva
Posts: 43
Joined: 02 Jun 2013 10:25

Re: how to supress directory too long messages

#3 Post by sambasiva » 17 May 2014 11:35

redirecting 2>nul and 1>nul didn't work for me.
Still I see those messages.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to supress directory too long messages

#4 Post by foxidrive » 17 May 2014 11:40

Try it again:


Code: Select all

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

sambasiva
Posts: 43
Joined: 02 Jun 2013 10:25

Re: how to supress directory too long messages

#5 Post by sambasiva » 18 May 2014 09:51

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to supress directory too long messages

#6 Post by foxidrive » 18 May 2014 09:57

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?

sambasiva
Posts: 43
Joined: 02 Jun 2013 10:25

Re: how to supress directory too long messages

#7 Post by sambasiva » 18 May 2014 10:35

Yes, I tried it.
Those messages are still there, however the stdout is empty.

Thanks
SS

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to supress directory too long messages

#8 Post by foxidrive » 18 May 2014 10:47

Is the folder on a network drive?

sambasiva
Posts: 43
Joined: 02 Jun 2013 10:25

Re: how to supress directory too long messages

#9 Post by sambasiva » 18 May 2014 21:46

No. This folder exists on the local disk itself. However this is a shared directory.

sambasiva
Posts: 43
Joined: 02 Jun 2013 10:25

Re: how to supress directory too long messages

#10 Post by sambasiva » 18 May 2014 22:54

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')

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: how to supress directory too long messages

#11 Post by penpen » 18 May 2014 23:35

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.
Last edited by penpen on 19 May 2014 06:20, edited 2 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to supress directory too long messages

#12 Post by foxidrive » 19 May 2014 05:24

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.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: how to supress directory too long messages

#13 Post by Aacini » 19 May 2014 05:47

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

sambasiva
Posts: 43
Joined: 02 Jun 2013 10:25

Re: how to supress directory too long messages

#14 Post by sambasiva » 20 May 2014 01:05

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

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: how to supress directory too long messages

#15 Post by Aacini » 20 May 2014 09:47

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!

Post Reply