Automatically Create Shortcuts - Search Recursively

Hi All,

Folder structure:

A\Stuff

A\Temp

B\Stuff

B\Temp

C\Stuff

C\Temp

D\Stuff

D\Temp

F\

What I want to do is script something that creates a shortcut for any files located in *\Stuff and create a shortcut that gets placed into F\

Thanks in advance

 

Question Info


Last updated June 27, 2019 Views 40 Applies to:

It is possibe to write such a script. The problem with scripts is that they need a very precise and tight specification. If the specification is loose then the script will fail.

Your specification is very loose. For example, it is not at all clear whether "C\Temp" really means "C:\Temp". It is also unclear what you mean with "located in *\Stuff", or where the shortcuts should go, or how the recursion should work. A precise specification might go like this:

  • Create a shortcut for each of the following folders:
    A:\Stuff
    B:\Stuff
    C:\Stuff
    etc.
    Z:\Stuff
  • Name the shortcuts "A-Stuff", "B-Stuff", "C-Stuff" etc.
  • Place the shortcuts on the desktop

Lastly - why not create the shortcuts manually? This would be much faster than creating a script!

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Are those drive letters or single-letter folder names? Does 'Stuff' have sub-folders? If so, do you want shortcuts to folders as well as files? Will F have sub-folders mirroring the folder structures of the other drives/folders or just a flat directory full of shortcuts? What about shortcuts that already exist in the source folders?

Keith

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Hi jjmadero

My name is Sarah Kong and I am an independent adviser that is here to try and help you with your issue.

Try putting your question in the Powershell forum.
see link and have a great day!

https://social.technet.microsoft.com/Forums/Win...

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

My mistake, that was a stupid way to write out my sample directory structure. Let's try again:

C:\Users\jmader\Documents\My Case Load\[CASE#]\Motions

C:\Users\jmader\Documents\My Case Load\[CASE#]\Media

C:\Users\jmader\Documents\My Case Load\[CASE#]\TrialMaterial

C:\Users\jmader\Documents\My Case Load\[CASE#]\Other

So CASE# refers to cases that are mine, each case parent directory has case has "Motions" "Media" "TrialMaterial" and "Other" subfolders.

I want to make symlinks for all files in the subfolders "Motions" (from each Case # parent directory) and place in:

C:\Users\jmader\Documents\Motions

Hopefully that's clearer

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Reply In reply to deleted message

That doesn't seem to be right....

set Source=C:\Users\jmader\Documents\My Case Load\[CASE#]\Motions

There is no such thing as CASE# (the brackets indicates that there are lots of case numbers, so I had ABC123, ABC124, ABC125, etc.....)


Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

That helps a lot.

Do you want actual symlinks (NTFS file system shortcuts) or are you OK with .lnk files (the kind created when you use 'Create Shortcut' in the Windows GUI))?

Do you want Case# subfolders under:

C:\Users\jmader\Documents\Motions?

If there are no subfolders, are the filenames unique enough that there will be no duplicate names? Copy the following into a PowerShell window for a quick check of the names:

gci "C:\Users\jmader\Documents\My Case Load\*\Motions" -file | select basename | sort basename

If there are tons of files, copy & paste the following. If all names are unique, there will be only one line in the results.

gci "C:\Users\jmader\Documents\My Case Load\*\Motions" -file | select basename | group basename | group count

Keith

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

If there are no duplicates and you don't need subfolders and you're OK with .lnk files, copy & paste the following into a PowerShell window:

$WshShell = New-Object -Comobject Wscript.shell

$WorkingFolder = 'C:\Users\jmader\Documents\Motions'

gci "C:\Users\jmader\Documents\My Case Load\*\Motions" -file |

%{

   $Shortcut = $WshShell.CreateShortcut("$WorkingFolder\$($_.baseName).lnk")

   $Shortcut.TargetPath = $_.FullName

   $Shortcut.Save()

 }

Keith

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

If you want symlinks, the code is simpler. But it has to be run from an Administrator PowerShell window. Also, the New-Item command threw some 'cannot find path...' errors --- but I was testing on my music files with a lot of odd characters in the filenames...but I got a ton of working symlinks.

$WorkingFolder = 'C:\Users\jmader\Documents\Motions'

gci "C:\Users\jmader\Documents\My Case Load\*\Motions" -file |

   %{New-item -path $WorkingFolder -name $_.BaseName -ItemType SymbolicLink -Value $_.FullName}

Keith

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.