Solved

Batch script: echo each path in new line

Posted on 2006-06-15
6
1,944 Views
Last Modified: 2008-02-01
I need a batch script that would echo each path in a new line. So far I have this which echoes all the paths in the same line:

FOR /F "tokens=* delims=;" %%A IN ('ECHO %path%') DO echo %%A

Thanks
0
Comment
Question by:gromul
  • 4
  • 2
6 Comments
 

Author Comment

by:gromul
ID: 16915693
Path can have one or more items
0
 

Author Comment

by:gromul
ID: 16915695
More specifically, 2+
0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 16921540
Assuming there are no semicolons in a path statement (it could theoretically happen ...), the following should work:

set Tail=%Path%
:loop
for /f "tokens=1* delims=;" %%a in ("%Tail%") do (
  echo %%a
  set Tail=%%b
  if not "%%b"=="" goto :loop
)
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:gromul
ID: 16924349
What do you mean "there are no semicolons in a path statement"? My path (echo %path%) looks something like this:

path1;path2;path3
0
 
LVL 84

Expert Comment

by:oBdA
ID: 16926527
That's okay, in that case, it's the regular delimiter for the different paths.
But theoretically, a semicolon could be part of a directory path:
%systemroot%\system32;%systemroot%;"C:\Some\Folder\with a ; in it";C:\Program Files\Acme
That's when it gets ugly, because the "for" command wouldn't care about the quotation marks around the directory, and break it up to
%systemroot%\system32
%systemroot%
"C:\Some\Folder\with a
in it"
C:\Program Files\Acme
Not that i can remember having ever come across a folder name with a semicolon in it, and it's even less likely for it to appear in a system's path, but just for the sake of completeness, it should be mentioned ...
0
 

Author Comment

by:gromul
ID: 16936528
All right. Thanks!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
outlook PST max size limit 3 137
Lock down IT Intern accounts 4 123
Archive .pst - Why my archive has only Inbox folder? 5 95
HP PC Hardware Diagnostics UEFI 11 178
Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question