Created
August 16, 2019 14:52
-
-
Save AnthonyVadala/65d5a86af76511e162dd543447cd1e80 to your computer and use it in GitHub Desktop.
PowerShell script to create a list of clickable URLs based on relative postion of files in a folder created for https://drv.tw/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ask user for directory input | |
$directorypath = Read-Host 'What is the directory path you want to create links for? (ex. C:\Users\UserName\OneDrive\Foldername)' | |
# Gets relative location for all files in given directory and saves to .txt file | |
Get-ChildItem -Path $directorypath -Recurse | Resolve-Path -Relative | Out-File index.html | |
# Reads index.html file to manipulate data | |
$filename = "index.html" | |
Get-ChildItem -File -Path $directorypath -Filter $filename -Recurse | ForEach { | |
# Removes leading .\ | |
(Get-Content $_ | ForEach { $_ -Replace "\.\\", "" }) | | |
Set-Content $_ | |
# Converts all \ characters to / | |
(Get-Content $_ | ForEach { $_ -Replace "\\", "/" }) | | |
Set-Content $_ | |
# Prepends URL to every line | |
(Get-Content $_ | ForEach { "<li><a href=`"https://YOURURLHERE.com/`">https://YOURURLHERE.com/" + $_ }) | | |
Set-Content $_ | |
(Get-Content $_ | ForEach { $_ + "</li>"}) | | |
Set-Content $_ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment