Skip to content

Instantly share code, notes, and snippets.

@jibbius
Created September 23, 2023 22:22
Show Gist options
  • Save jibbius/eac317486e996e5a86350ff258f73ad1 to your computer and use it in GitHub Desktop.
Save jibbius/eac317486e996e5a86350ff258f73ad1 to your computer and use it in GitHub Desktop.
Reorganise Humble Bundle Book downloads
# Step 1
# ------
# Open Powershell ISE
# - If you encounter permissions errors, Run as Administrator, then use the command:
# Set-ExecutionPolicy RemoteSigned
# Step 2
# ------
# Download everything using this FireFox plugin:
# - https://addons.mozilla.org/en-US/firefox/addon/humble-bundle-downloader/
# Step 3
# ------
# Set the names of directories:
$my_dir_one = 'D:\Downloads\HumbleBundle\Databases And Data Management'
$my_dir_two = 'D:\Downloads\HumbleBundle_Sorted'
# Step 4
# ------
# Use the script below to reorganise the files:
$files = Get-ChildItem $my_dir_one -Recurse -Include * -Attributes !Directory
$files = $files | Sort-Object -Property BaseName
foreach ($f in $files){
echo $f.BaseName
# Use filename to generate directory name
$target_dir = $my_dir_two + '\' + $f.BaseName
if (Test-Path $target_dir) {
# Folder already exists
} else {
New-Item $target_dir -ItemType Directory
}
# Determine target filename:
$source_filename = $f.FullName
$target_filename = $target_dir + '\' + $f.Name
# Copy to the new location:
Copy-Item -Path $source_filename -Destination $target_filename
# Alternatively, move to the new location:
#Move-Item -Path $source_filename -Destination $target_filename
}
@jibbius
Copy link
Author

jibbius commented Sep 23, 2023

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment