Command Output handle emtpy Line in FOR Loop
Moderator: DosItHelp
Command Output handle emtpy Line in FOR Loop
##################
F:\>for /F "skip=1 tokens=1" %d in ('WMIC logicaldisk where VolumeName="BACKUP150108" get caption') do echo backupdrive="%d"
F:\>echo backupdrive="F:"
backupdrive="F:"
" \>echo backupdrive="
"ackupdrive="
##################
The command "WMIC logicaldisk where VolumeName="BACKUP150108" get caption" on the commandline returns:
Caption
F:\
Prompt:>
##################
I would like to output backupdrive="F:" only
not "ackupdrive=".
In the for statement it is possible to skip the first line (Caption) but my Problem is the last line. What must be defined in the do statement to exclude linebreak ?
thanks Bastian
F:\>for /F "skip=1 tokens=1" %d in ('WMIC logicaldisk where VolumeName="BACKUP150108" get caption') do echo backupdrive="%d"
F:\>echo backupdrive="F:"
backupdrive="F:"
" \>echo backupdrive="
"ackupdrive="
##################
The command "WMIC logicaldisk where VolumeName="BACKUP150108" get caption" on the commandline returns:
Caption
F:\
Prompt:>
##################
I would like to output backupdrive="F:" only
not "ackupdrive=".
In the for statement it is possible to skip the first line (Caption) but my Problem is the last line. What must be defined in the do statement to exclude linebreak ?
thanks Bastian
Re: Command Output handle emtpy Line in FOR Loop
Code: Select all
for /f "skip=1" %d in ('wmic logicaldisk where VolumeName^="BACKUP150108" get caption') do @for /f %e in ("%d") do @echo backupdrive="%e"
Re: Command Output handle emtpy Line in FOR Loop
Yury wrote:Code: Select all
for /f "skip=1" %d in ('wmic logicaldisk where VolumeName^="BACKUP150108" get caption') do @for /f %e in ("%d") do @echo backupdrive="%e"
I spent a half hour this morning trying to figure that out. Never dawned on me to use a 2nd FOR command but now it makes perfect SENSE!
Re: Command Output handle emtpy Line in FOR Loop
Squashman wrote:I spent a half hour this morning trying to figure that out. Never dawned on me to use a 2nd FOR command but now it makes perfect SENSE!
Actually we discussed that issue several times before
E.g. viewtopic.php?f=3&t=4266
Regards
aGerman
Re: Command Output handle emtpy Line in FOR Loop
My brain is crammed with too many things!
Re: Command Output handle emtpy Line in FOR Loop
Squashman wrote:My brain is crammed with too many things!
yeah, I have that problem too.
When I walk down to buy milk, I'm sure that I leave a trail of things on the road that fall out, never to be remembered again.
Re: Command Output handle emtpy Line in FOR Loop
Moinsen,
thanks for the answers:
1.Problem: I try to access "%a" on second subroutine - is there another way???
2.Problem: In a batch script i get a (german) syntax error "kann syntaktisch an dieser Stelle nicht verarbeitet werden." (i copy & paste the statement)
I´m going crazy of that. I suspect my Problems are already known und solved, but i am at a loose for match search-words. Sorry for that
...not the correct result... replace %a to "d:"
... much better...
... and the second prob wait for me
thanks for the answers:
1.Problem: I try to access "%a" on second subroutine - is there another way???
2.Problem: In a batch script i get a (german) syntax error "kann syntaktisch an dieser Stelle nicht verarbeitet werden." (i copy & paste the statement)
I´m going crazy of that. I suspect my Problems are already known und solved, but i am at a loose for match search-words. Sorry for that
Code: Select all
E:\>for /f "tokens=*" %a in ( 'WMIC logicaldisk where "drivetype=3 and VolumeNam
e!='BACKUP15012015'" get caption ^| findstr ":"' ) do for /f "tokens=1,2" %b in
('dir %a*_#. /ad /b') do @call echo [%b]
\*_#. /ad /b') do @call echo [%b] r C:
Datei nicht gefunden
[$Recycle.Bin]
[BACKUP]
[Config.Msi]
[Documents]
[Dokumente]
[Downloads]
[HDW30_TMP]
[KMUPDcache]
[MSOCache]
[Novell]
[PerfLogs]
[Program]
[Program]
[ProgramData]
[Programme]
[Recovery]
[savsa]
[System]
[Temp]
[test.{ED7BA470-8E54-465E-825C-99712043E01C}]
[Users]
[Windows]
[wsusconf]
\*_#. /ad /b') do @call echo [%b] r D:
Datei nicht gefunden
[$RECYCLE.BIN]
[22.02.2011]
[BR_SHARK]
[Cruzer]
[DOKUMENTE]
[DVD]
[FRAMESERVER]
[handyvideos]
[HDtmp]
[inf]
[inf2]
[INSTALL]
[kon2]
[mods_#]
[Neuer]
[Neuer]
[openldap]
[psexec]
[System]
[teamviewer]
[test]
[tidow_FB01]
[tmp]
[VPIN]
[WOL]
[xampp]
...not the correct result... replace %a to "d:"
Code: Select all
E:\>for /f "tokens=*" %a in ( 'WMIC logicaldisk where "drivetype=3 and VolumeNam
e!='BACKUP15012015'" get caption ^| findstr ":"' ) do for /f "tokens=1,2" %b in
('dir d:\*_#. /ad /b') do @call echo [%b]
E:\>for /F "tokens=1,2" %b in ('dir d:\*_#. /ad /b') do @call echo [%b]
[mods_#]
E:\>for /F "tokens=1,2" %b in ('dir d:\*_#. /ad /b') do @call echo [%b]
[mods_#]
... much better...
Code: Select all
E:\>backup_.bat
""' ) do for /f "tokens" kann syntaktisch an dieser Stelle nicht verarbeitet wer
den.
E:\>for /f "tokens=*" "' ) do for /f "tokens=1,2" a\*_#. /ad /b') do @call echo
[b]
E:\>
... and the second prob wait for me
Re: Command Output handle emtpy Line in FOR Loop
new day new point of view. Here my finished script with findstr solution. Thanks for now.
Code: Select all
set robostr=/S /V /ZB /R:1 /W:1 /LOG+:Backup.log
set backupdrivevolname=BACKUP15012015
set backupmarker=*_#.
@echo off
for /f "delims=" %%A in ('WMIC logicaldisk where VolumeName^=^'%backupdrivevolname%^' get caption ^| findstr ^:') do @for /f "delims=:" %%B in ("%%A") do @set backupdrive=%%B
if X%backupdrive%X == XX (echo Kein Backuplaufwerk gefunden. Bitte pruefen ob ein Laufwerk mit der Bezeichnung: %backupdrivevolname% vorhanden ist.
)else (
echo Backuplaufwerk Bezeichnung: %backupdrivevolname% und Laufwerksbuchstaben: %backupdrive%: gefunden.
for /f "delims=" %%A in ('WMIC logicaldisk where ^(drivetype^=3 and VolumeName^!^=^'%backupdrivevolname%^'^) get caption ^| findstr ^:') do (
@for /f "delims=:" %%B in ("%%A") do (
echo Durchsuche Laufwerk %%B: nach zu sichernden Ordnern
echo die Zeichenkette %backupmarker% am Ende enthalten.
echo Befehl: dir %%B:\%backupmarker% /ad /b /s
for /f "tokens=1" %%C in ('dir %%B:\%backupmarker% /ad /b /s') do (
echo Befehl: robocopy %%B:\%%C \%COMPUTERNAME%\%%B\%%C %robostr%
robocopy %%B:\%%C \%COMPUTERNAME%\%%B\%%C %robostr%
)
)
)
)