I'm writing a Batch file (.bat) and I couldn't find a way to discover if a given directory I have the path to is a real directory or a Junction (created on Windows 7 by using mklink /j
). Can anyone point me in the right direction?
&& runs the second command on the line when the first command comes back successfully (i.e. errorlevel == 0 ). The opposite of && is || , which runs the second command when the first command is unsuccessful (i.e. errorlevel != 0 ).
The %* modifier is a unique modifier that represents all arguments passed in a batch file. You cannot use this modifier in combination with the %~ modifier. The %~ syntax must be terminated by a valid argument value. Source: "Using batch parameters" on Microsoft.com (defunct)
The Test-Path Cmdlet $Folder = 'C:\Windows' "Test to see if folder [$Folder] exists" if (Test-Path -Path $Folder) { "Path exists!" } else { "Path doesn't exist." } This is similar to the -d $filepath operator for IF statements in Bash. True is returned if $filepath exists, otherwise False is returned.
In a batch script you can use the following:
SET Z=&& FOR %%A IN (linkfilename) DO SET Z=%%~aA
IF "%Z:~8,1%" == "l" GOTO :IT_A_LINK
this is quicker than calling DIR /AL
.
The %%~aA
gets the attributes of the "linkfilename",
a 9 char string like d--------
(a directory),
or d-------l
a link to a directory,
or --------l
a link to a file.
%Z:~8,1%
then grabs just the reparse point attribute.
I have this little gem which will list all Junctions and their targets in your current directory:
for /F "delims=;" %j in ('dir /al /b') do @for /F "delims=[] tokens=2" %t in ('dir /a ^| findstr /C:"%j"') do @echo %j :: %t
Example output:
Application Data :: C:\Users\AB029076\AppData\Roaming
Cookies :: C:\Users\AB029076\AppData\Roaming\Microsoft\Windows\Cookies
Local Settings :: C:\Users\AB029076\AppData\Local
My Documents :: C:\Users\AB029076\Documents
NetHood :: C:\Users\AB029076\AppData\Roaming\Microsoft\Windows\Network Shortcuts
PrintHood :: C:\Users\AB029076\AppData\Roaming\Microsoft\Windows\Printer Shortcuts
Recent :: C:\Users\AB029076\AppData\Roaming\Microsoft\Windows\Recent
SendTo :: C:\Users\AB029076\AppData\Roaming\Microsoft\Windows\SendTo
Start Menu :: C:\Users\AB029076\AppData\Roaming\Microsoft\Windows\Start Menu
Templates :: C:\Users\AB029076\AppData\Roaming\Microsoft\Windows\Templates
TestLink :: C:\Users\AB029076\AppData\Roaming\Microsoft\Windows\Network Shortcuts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With