Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3342420
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:50:11+00:00 2026-05-18T00:50:11+00:00

I tried to write a small script to automate the creation of playlists (m3u)

  • 0

I tried to write a small script to automate the creation of playlists (m3u) for dozens of folders/subfolders of mp3/mp4 files, while omitting various other misc files therein. I know very little about Powershell but managed to piece together something that almost works. The only blip is that when I use “$_.extension -eq”, it doesn’t seem to work, or at least I’m not using it right. If I use it to match log/txt files in a temp folder for example, it works, but not in this instance. Here is the code –

$pathname = read-host "Enter path"
$root = Get-ChildItem $pathname | ? {$_.PSIsContainer}
$rootpath = $pathname.substring(0,2)
Set-Location $rootpath
Set-Location $pathname
foreach($folder in $root) {
Set-Location $folder
foreach($file in $folder) {
$txtfile =".m3u"
$files = gci | Where-Object {$_.extension -eq ".mp3" -or ".mp4"}
$count = $files.count
if($count -ge 2){
$txtfile = "_" + $folder.name + $txtfile
Add-Content $txtFile $files
}  
}
if(test-path $txtFile){
Add-Content $txtFile `r
}
Set-Location $pathname
}

I have tried several variations like swapping “-match” for “-eq” but no luck. incidentally, if I omit the “-or “.mp4″” from the parentheses then it works fine, but I need it to match both, and only both mp3/mp4.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:50:12+00:00Added an answer on May 18, 2026 at 12:50 am

    As far as you complain about extension, let’s start with it. Presumably there is a bug in the code; this expression/syntax is technically valid:

    $_.extension -eq ".mp3" -or ".mp4"
    

    But apparently the intent was:

    $_.extension -eq ".mp3" -or $_.extension -eq ".mp4"
    

    Try the corrected expression at first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to write a script to list all files in directories and subdirectories
I've recently tried to write a small scraping script with Ruby and Capybara; however,
I'm trying to write a small Python script that will get query results from
I'm trying to write a small script which parses and executes Brainfuck code, to
I would like to write a small notification script using python watchdog for windows.
I tried to write a function to check key code with JavaScript. It's working
I tried to write a function that calculates a hamming distance between two codewords
I tried to write a Neural Network system, but even running through simple AND/OR/NOR
I tried to write a program that uses threads, but couldn't understand the o/p.
I tried to write a Taylor series expansion for exp(x)/sin(x) using fortran, but when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.