I'm trying to write a script that will find all directory junctions on a disk and then recreate them in another location. First of all, I have to find all the junctions and edit the output to be more readable.
This is the test.txt:
Volume in drive C has no label.
Volume Serial Number is A0D2-DFB0
Directory of C:\
14.07.2009. 06:08 <JUNCTION> Documents and Settings [C:\Users]
13.01.2015. 10:26 <JUNCTION> Users [E:\Users]
0 File(s) 0 bytes
Directory of C:\ProgramData
14.07.2009. 06:08 <JUNCTION> Application Data [C:\ProgramData]
14.07.2009. 06:08 <JUNCTION> Desktop [C:\Users\Public\Desktop]
14.07.2009. 06:08 <JUNCTION> Documents [C:\Users\Public\Documents]
14.07.2009. 06:08 <JUNCTION> Favorites [C:\Users\Public\Favorites]
14.07.2009. 06:08 <JUNCTION> Start Menu [C:\ProgramData\Microsoft\Windows\Start Menu]
14.07.2009. 06:08 <JUNCTION> Templates [C:\ProgramData\Microsoft\Windows\Templates]
0 File(s) 0 bytes
Directory of C:\ProgramData\Oracle\Java\javapath
24.12.2014. 18:22 <SYMLINK> java.exe [D:\Programs\Java 8u25\bin\java.exe]
24.12.2014. 18:22 <SYMLINK> javaw.exe [D:\Programs\Java 8u25\bin\javaw.exe]
24.12.2014. 18:22 <SYMLINK> javaws.exe [D:\Programs\Java 8u25\bin\javaws.exe]
3 File(s) 0 bytes
Total Files Listed:
3 File(s) 0 bytes
8 Dir(s) 16.309.276.672 bytes free
- This is the (unfinished) script that I'm running:
echo on
cd \
set start=
set end=
set paths=
type NUL > output.txt
for /f "tokens=* skip=3" %%l in (C:\test.txt) do (
for /f "tokens=1" %%d in ("%%l") do (
if %%d==Directory (
for /f "tokens=3" %%p in ("%%l") do (
set start="%%p"
)
) else (
for /f "tokens=3" %%j in ("%%l") do (
if %%j==^<JUNCTION^> (
for /f "tokens=4*" %%h in ("%%l") do (
set end="%%h"
echo %start% %end% >> output.txt
)
)
)
)
)
)
Problem is that output.txt ends up with several lines of "Echo is ON" instead of having paths in there. If I substitute "%start% %end%" with any string (eg. "sausage") I get output.txt filled with sausages. If I run echo set %end% after the script runs, output is "Templates" which is expected. I'm guessing that set command doesn't set anything until one of the loops is done.
Am I right? Is there a way around that? I really need to get this working in CMD because it has to be run from Windows Repair disk.
P.S. I know my code won't work for my purpose even with this program fixed, but I'm just getting there, first things first.