2
I need a regular shortcut or a .bat located in C:\abc\00001\ It should link to C:\xyz\00001\ , where the 00001 is treated as a relative expression, in this case "current directory name".
The aim is to quickly accessing a "sister folder", whether the folder name is 00001 or 12734 or 96185 etc etc. The real paths will be far away from each other in the folder tree.
Ideally, it would not be a bat file but a regular windows shortcut, but I couldn't get any kind of %CurrDirName% to work.
I tried searching and came up with some code that maybe could be adjusted for the purpose, but I have little experience with this type of syntax..
Get the current directory name (where the bat file is located; C:\abc\00001\ should give 00001)
for %%* in (.) do set CurrDirName=%%~nx*
Open the corresponding remote directory (C:\xyz\00001)
%SystemRoot%\explorer.exe "c:\xyz\%CurrDirName%"
Any takes? :)
EDIT: Thanks to @davidmneedham I ended up using a VBscript. Here is my final code:
Set objShell = CreateObject("Wscript.Shell")
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFSOexists = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile)
strExchangeThis = "Y:\Organization\...\" 'shortened path!
strToThis = "Y:\Labspace\...\" 'shortened path!
strRelFolder = Replace(strFolder, strExchangeThis, strToThis)
' if strRelFolder does not exist yet, we should instead be lead to the basic strToThis folder
exists = objFSOexists.FolderExists(strRelFolder)
if Not (exists) then
strRelFolder = strToThis
end if
strPath = "explorer.exe /e," & strRelFolder
objShell.Run strPath
' Encoding changed from UTF-8 to ANSI to allow danish characters in strings.
Hi David, thank you- that's a great start. :) It works perfectly when the folder structure is simple
SET newpath=%cd:\ERWI\=\ERWI2\% start %newpath%
, but I run into problems when trying to adjust to a more advanced pathway, as I just added as a comment to my original question. To begin with, my attempt on simple double quotes messes it up..SET newpath=%cd:"\ERWI\"="\ERWI2\%"
as well asSET newpath=%cd:"\ERWI\"="\ERWI2\"%
– erwi1313 – 2018-04-11T08:58:07.697Hi again - sorry I removed my first comment just before you posted. You're correct - I had mistakingly forgotten to remove quotation marks, trying to fix my new problem. :) – erwi1313 – 2018-04-11T08:59:23.117
The VBScript executed wonderfully on the simple folder paths, so I will try to adapt it for the complex paths as well. I have a bit more experience with VBScript than command prompts, so I'll try to figure it out. Thank you so much!! I will be loved for this at work!! :) – erwi1313 – 2018-04-11T09:26:41.477
1Yes!! I've gotten everything to work perfectly with the VBscript and it so smoooooth! Danish characters made a fuzz, but was solved by changing from UTF-8 to ANSI. Also, I used a "if FolderExists" to see if the sister folder had been created yet. If not, you're just sent to the "overview folder". Thank you so much for the backbone to my script!! – erwi1313 – 2018-04-11T13:49:25.240