Saturday, March 23, 2024

Replace characters in folder names using Windows PowerShell

This article describes a method to rename folders by replacing a character with another. In this use case we have a folder full of subfolders which are named in a particular pattern with a date followed by the description of the folder. The words in the folder names are separated by the hyphen ("-') character.  Our objective is to keep the date part intact while replacing all the hyphens after the data with whitespace characters.

The before and after state of the folder names are illustrated in the screenshot below.

Renamed folders with hyphens replaced with whitespace characters

For this example, we consider that our bunch of folders are in a local drive path named "C:\Users\SampleUser\Desktop\2006".

Open the Windows PowerShell and change directory to "C:\Users\SampleUser\Desktop\2006". Next run the following script at the prompt. Remember to set the value of $directoryPath below to the appropriate path according to your situation:

# Set the directory path where you want to rename folders
$directoryPath = "C:\Users\SampleUser\Desktop\2006"

# Get a list of all folders in the specified directory
$folders = Get-ChildItem -Path $directoryPath -Directory

# Loop through each folder
foreach ($folder in $folders) {
    # Check if folder name is longer than 10 characters and contains '-'
    # character at position 11
    if ($folder.Name.Length -ge 11 -and $folder.Name.Substring(10, 1) `
    -eq "-") {
        # Construct the new folder name by replacing '-' with a blank
        # space starting at character number 11
        $newName = $folder.Name.Substring(0, 10) + `
        ($folder.Name.Substring(10) -replace '-', ' ')
       
        # Get the full path of the old and new folder names
        $oldPath = Join-Path -Path $directoryPath -ChildPath $folder.Name
        $newPath = Join-Path -Path $directoryPath -ChildPath $newName
       
        # Rename the folder
        Rename-Item -Path $oldPath -NewName $newName -ErrorAction SilentlyContinue
        Write-Host "Renamed folder: $($folder.Name) to $($newName)"
    }
}

On successful execution of this script, you should see an output like this.

Renamed folder: 2019-01-16-Travel-to-France to 2019-01-16 Travel to France
Renamed folder: 2019-03-07-Meijer to 2019-03-07 Meijer
Renamed folder: 2019-05-04-National-Train-Day to 2019-05-04 National Train Day
Renamed folder: 2019-05-18-Woodland-Park to 2019-05-18 Woodland Park
Renamed folder: 2019-05-26-Maumee-Bay-State-Park to 2019-05-26 Maumee Bay State Park
Renamed folder: 2019-07-05-African-Safari-Wildlife-Park to 2019-07-05 African Safari Wildlife Park

Now you are done.


Saturday, March 16, 2024

Unmasked: The Final Years of Michael Jackson by Ian Halperin

Michael Jackson, the King of Pop, remains one of the most enigmatic figures in music history. Even in death, his legacy continues to captivate audiences worldwide. Ian Halperin's book, "Unmasked: The Final Years of Michael Jackson," delves into the intricate details of the superstar's life, shedding light on the controversies, struggles, and triumphs that defined his last years.

At the heart of Halperin's narrative lies an exploration of Jackson's personal and professional life. The book paints a complex portrait of a man who, despite his unparalleled success, grappled with intense scrutiny and relentless media attention. From his meteoric rise to stardom with the Jackson 5 to his iconic solo career, every aspect of Jackson's journey is meticulously examined.

One of the most compelling aspects of "Unmasked" is its exploration of Jackson's relationships. Halperin offers insight into the singer's tumultuous marriages, friendships, and familial bonds, highlighting the profound impact they had on his life and career. Through interviews and research, the author uncovers the dynamics behind Jackson's closest connections, revealing both the joys and challenges that accompanied them.

Moreover, "Unmasked" delves into the controversies that plagued Jackson in his later years. From allegations of child molestation to financial troubles, Halperin confronts the difficult questions surrounding the superstar's legacy. While acknowledging Jackson's undeniable talent and contributions to music, the book does not shy away from addressing the darker aspects of his life, providing readers with a comprehensive understanding of the man behind the legend.

Throughout the book, Halperin offers valuable insights into Jackson's psyche, shedding light on the psychological and emotional factors that shaped his behavior. By examining Jackson's upbringing, experiences, and influences, the author paints a nuanced portrait of a deeply complex individual struggling to reconcile fame, fortune, and personal demons.

One of the most poignant themes explored in "Unmasked" is Jackson's quest for acceptance and validation. Despite his immense success, Jackson grappled with feelings of loneliness and isolation, seeking refuge in his music and creative pursuits. Through Halperin's narrative, readers gain a deeper understanding of the pressures and expectations that weighed heavily on the superstar, driving him to seek solace in unconventional ways.

Ultimately, "Unmasked" offers readers a thought-provoking glimpse into the final years of Michael Jackson's life. By presenting a comprehensive overview of the superstar's journey, Halperin invites readers to reevaluate their perceptions and assumptions about one of the most iconic figures in music history. Whether you're a die-hard fan or a casual observer, this book is sure to leave a lasting impression, challenging you to consider the complexities of fame, fortune, and the human spirit.

In conclusion, "Unmasked: The Final Years of Michael Jackson" is a must-read for anyone interested in understanding the man behind the music. Through meticulous research and compelling storytelling, Ian Halperin offers readers a front-row seat to the trials and tribulations of a musical legend, leaving an indelible mark on the landscape of pop culture history.

Here is my note at Goodreads:

Unmasked: The Final Years Of Michael JacksonUnmasked: The Final Years Of Michael Jackson by Ian Halperin
My rating: 4 of 5 stars

This book provides a detailed examination of the later years of the iconic pop star's life. Drawing on interviews, research, and firsthand accounts, the book delves into Jackson's personal and professional struggles, including his health issues, legal battles, and financial challenges. Halperin explores various controversies surrounding Jackson, shedding light on his relationships, lifestyle, and legacy. The narrative offers readers an in-depth perspective on the complexities of Jackson's life, presenting a balanced portrayal of the superstar's final years without necessarily taking a definitive stance on his actions or character.



View all my reviews