0

I have a bunch of folders with similar prefixes in the name, and I'd like to make symbolick links to these folders so that I can remove the prefix while respecting the original folder naming convention. Here are some example folder names:

2013.Folder1
2013.Folder2
2014.Folder1

in the folder:

C:\Users\madeupname\Documents

In linux, I'd just do

ln -s /home/madeupname/Documents/201* /home/madeupname/Documents/links/

(this code may not exactly right as I don't have a linux box handy right now)

In Windows PowerShell, I could do it manually for these 3 files:

cmd /c mklink C:\Users\madeupname\Documents\links\2013.Folder1 C:\Users\madeupname\Documents\2013.Folder1

but that is no good because the real directory has a lot of files!

2
  • I just noticed this is very similar to stackoverflow.com/questions/19754171/… but it seems like there must be a simpler, more elegant way to do this than the accepted answer. Commented May 8, 2014 at 14:23
  • When the shell interprets a '*' it's called globbing. The asterisk in that case is called wildcard, not regex. Here's a powershell glob question Commented Apr 28, 2022 at 23:38

2 Answers 2

0

if I understood correctly this can work for you:

$path = "C:\Users\madeupname\Documents"

dir $path -Directory | 
% { cmd /c mklink C:\Users\madeupname\Documents\links\$_.name $_.fullname /d}
Sign up to request clarification or add additional context in comments.

2 Comments

No luck. Using PowerShell ISE, I get: Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'. At line:3 char:21 + dir $path -Directory <<<< | + CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
The -Directory was added in v3 I think. Instead do dir $path | ?{$_.PSIsContainer} | %{cmd /s mklink c:\users\madeupname\documents\links\$_.name $_.fullname /d} Also, if this is for the current user you can make that more reliable by replacing c:\users\madeupname with $env:userprofile
0

I found a GUI to do this, but that's cheating so I won't mark this as the answer:

http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.