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!

Chad
  • 1,434
  • 1
  • 15
  • 30
  • I just noticed this is very similar to http://stackoverflow.com/questions/19754171/how-to-create-symbolic-links-for-multiple-files-in-multiple-folders-using-comman?rq=1 but it seems like there must be a simpler, more elegant way to do this than the accepted answer. – Chad May 08 '14 at 14:23
  • When the shell interprets a '\*' it's called [globbing](https://www.linuxjournal.com/content/globbing-and-regex-so-similar-so-different). The asterisk in that case is called *wildcard*, not regex. Here's a [powershell glob question](/q/70355772) – cachius Apr 28 '22 at 23:38

2 Answers2

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}
CB.
  • 58,865
  • 9
  • 159
  • 159
  • 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 – Chad May 08 '14 at 17:38
  • 1
    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` – TheMadTechnician May 08 '14 at 18:16
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

Chad
  • 1,434
  • 1
  • 15
  • 30