xen111

New Member
Joined
Nov 10, 2013
Messages
1
I haven't done any programming for a long time, and virtually haven't done any Windows scripting since the days of MS-DOS.

For my digital audio needs I am planning to separate my music collection into 3 folder trees:
- lossless albums
- lossy albums inclusive
- lossy albums exclusive.

The lossless (FLAC) albums and the lossy (MP3) inclusive albums will be combined into a single library for every kind of jukebox software I use, ie. currently Winamp and Squeezebox. These two collections are disjunctive, they do not overlap. The combined view won't have duplicates.

The exclusive lossy albums are albums of which I have a FLAC version as well. This means "lossless + inclusive = all albums I have", "inclusive + exclusive = all lossy albums I have" and "lossless + exclusive = identical set".

In particular for this to work, I need a way to combine the inclusive and exclusive trees so I can at least copy albums from it to mobile players or other uses that require small file size.

In linux, I would simply create a 'virtual' tree consisting just of symbolic links to all the directories in all of the two trees. I would write a shell script that would create, update and delete these symbolic links. I'm not sure however if this would allow me to copy the actual directories (and not just the symlinks).

I'm looking to achieve the same thing in Windows. What kind of scripting would you use for this? What is easiest to achieve? I know that it is possible to create a kind of symbolic links.

I tried to use Cygwin some time ago for something unrelated, but either I was doing it all wrong, or it didn't work at all - especially ran into problems with files that had spaces and trying to escape these spaces. All that fun.

Can you point me in the right direction?
 

Solution
To achieve the folder organization and linkage you described in Windows, you can use PowerShell scripting. PowerShell is a powerful scripting language that allows you to automate tasks and manage the Windows operating system efficiently. Here's a general approach you can take to set up the directory structure you need with symbolic links in Windows:
  1. Create the Folder Structure:
    • First, organize your music collection into the three main folders: lossless albums, lossy albums inclusive, and lossy albums exclusive.
    • Make sure the albums are appropriately categorized in each folder.
    []Create Symbolic Links:
    • Use PowerShell to create symbolic links from the inclusive and exclusive folders to a combined...
To achieve the folder organization and linkage you described in Windows, you can use PowerShell scripting. PowerShell is a powerful scripting language that allows you to automate tasks and manage the Windows operating system efficiently. Here's a general approach you can take to set up the directory structure you need with symbolic links in Windows:
  1. Create the Folder Structure:
    • First, organize your music collection into the three main folders: lossless albums, lossy albums inclusive, and lossy albums exclusive.
    • Make sure the albums are appropriately categorized in each folder.
    []Create Symbolic Links:
    • Use PowerShell to create symbolic links from the inclusive and exclusive folders to a combined view folder.
    • Symbolic links in Windows will allow you to reference the original folders without duplicating the files.
    [
    ]PowerShell Scripting:
    • Write a PowerShell script that creates symbolic links in a new directory for the combined view based on the contents of the inclusive and exclusive folders.
    • Ensure that the script handles spaces in file names correctly. Here's a simplified example of how you can use PowerShell commands to create symbolic links:
      Code:
      # Define paths to your three main folders $losslessPath = "C:\Music\Lossless" $inclusivePath = "C:\Music\Lossy Inclusive" $exclusivePath = "C:\Music\Lossy Exclusive" $combinedViewPath = "C:\Music\Combined View" # Create symbolic links for inclusive and exclusive albums in the combined view New-Item -ItemType SymbolicLink -Path $combinedViewPath -Name "Inclusive" -Value $inclusivePath New-Item -ItemType SymbolicLink -Path $combinedViewPath -Name "Exclusive" -Value $exclusivePath # You can also loop through the folders in the inclusive and exclusive directories to create symbolic links for individual albums
      This script is a basic starting point. You can extend it to include looping through the folders in the inclusive and exclusive directories to create symbolic links for individual albums. For handling spaces in file names, PowerShell supports quoting paths that include spaces, which should help avoid issues with file names containing spaces. Feel free to adjust and expand upon this script based on your specific folder structure and requirements. PowerShell scripting provides a flexible and robust way to manage file operations and symbolic links in Windows. Let me know if you need further assistance or more detailed guidance on any specific aspect of this process!
 

Solution
Hi kemiy!
Using symbolic links (mklink) is indeed a fantastic way to create a "virtual" tree on Windows for combining your inclusive and exclusive album folders. Here's a detailed guide to help achieve your goal:

Step 1: Understanding mklink

mklink is a built-in command in Windows that allows you to create symbolic links, which act as pointers to files or directories without duplicating them.
  • Types of Links:
    • Symbolic Links: Point to a file or folder and act like shortcuts.
    • Junctions: Similar but slightly older, only usable for directories.
    • Use symbolic links for the greatest flexibility.

Step 2: Manually Create Symbolic Links

Let’s say you want to create symbolic links for your "inclusive" and "exclusive" album directories inside a single "combined" folder.
  1. Syntax for Folders:
    Code:
    cmd
    mklink /D "C:\Path\To\Combined\Album1" "C:\Path\To\Inclusive\Album1"
    This creates a symbolic link in the Combined folder pointing to Album1 in the Inclusive directory.
  2. Process:
    • Open Command Prompt in Administrator mode.
    • Use the mklink /D command for each directory you want to link.

Step 3: Automating with PowerShell

For many albums, manual linking is tedious. A PowerShell script can automate the process.
Code:
# Define the paths
$inclusiveFolder = "C:\Path\To\Inclusive"
$exclusiveFolder = "C:\Path\To\Exclusive"
$combinedFolder = "C:\Path\To\Combined"
[HEADING=1]Ensure the combined folder exists[/HEADING]
if (!(Test-Path $combinedFolder)) {
New-Item -ItemType Directory -Path $combinedFolder
}
[HEADING=1]Loop through directories and create symbolic links[/HEADING]
foreach ($folder in Get-ChildItem -Directory -Path $inclusiveFolder, $exclusiveFolder) {
$linkPath = Join-Path -Path $combinedFolder -ChildPath $folder.Name
cmd /c mklink /D "$linkPath" "$($folder.FullName)"
}
  • What it does:
    • Loops through both inclusive and exclusive folders.
    • Automatically creates symbolic links in the combined folder.

Step 4: Copy Files from Virtual Tree

If you want to physically copy the files instead of just linking them, use Robocopy or xcopy.

Example 1: Robocopy​

Code:
robocopy "C:\Path\To\Combined" "C:\Destination\Path" /E
  • /E: Copies all subdirectories and files, including empty folders.
  • This command resolves symbolic links by copying the actual files.

Example 2: Xcopy​

Code:
xcopy "C:\Path\To\Combined" "C:\Destination\Path" /E /H
  • /E: Copies directories including empty ones.
  • /H: Ensures hidden files and folders are also copied.

Step 5: Considerations for Spaces in File Paths

If your folder names contain spaces:
  • Surround paths with double quotes ("C:\Path With Spaces").
  • When using PowerShell scripts, paths with spaces are already handled.

Step 6: A Word About Cygwin

While Cygwin can create symbolic links, it’s often unnecessary for this use case as Windows’ mklink is more approachable and directly integrates into the OS.

Final Thoughts

Symbolic links combined with PowerShell automation or Robocopy give you a lot of flexibility in managing the virtual tree of albums. It’s efficient and avoids duplicating data, which saves both time and storage space.
If you need help refining the script or handling specific scenarios, feel free to ask! 🎵💻✨
 

Back
Top