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

  • Home
  • SEARCH
  • 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 7009477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:52:02+00:00 2026-05-27T21:52:02+00:00

I am trying to write a script that will parse a directory, find the

  • 0

I am trying to write a script that will parse a directory, find the 3 newest files of a given extension among other files with the same name but different extension and then pass the output to a command line program.

So far I have:

$file = dir test -Exclude *.md5 | sort -prop LastWriteTime | select fullname -last 3
\path\program argumentA $file[0] argumentB "argumentC"
\path\program argumentA $file[1] argumentB "argumentC"
\path\program argumentA $file[2] argumentB "argumentC"

Not sure if it matters a whole lot but argument2 needs to be in quotes for the program to use it. I will eventually either have the output written to a file or, preferably use the output in another line of code described in the bonus question.

The problem I am having is that when I use $file[0] as an argument nothing happens. When I use the file name stored in $file[0] instead of using the variable, it runs, but does not pass argumentB or argumentC. If I run it from cmd I get the proper output.

My questions are:
How do I get the program to recognize a variable?
How do I get the program to recognize the other arguments?

Bonus question:
The program will output a list of files. How do I delete everything in the given folder except for the files listed in the output of the program?

  • 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-27T21:52:02+00:00Added an answer on May 27, 2026 at 9:52 pm

    Try

    $($file[0])
    

    I find that I often have to wrap things in “magical” dollar sign brackets to get them working in PowerShell.

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

Sidebar

Related Questions

I'm trying to write a Perl script that will parse the output of the
I'm trying to write a script that will download files from an FTP server.
I'm trying to write a bash script that will process a list of files
I am trying to write a script that will parse a local file and
I'm trying to write a script that will find a particular process based on
I am trying to write a script that will find all <a> tags whose
I'm trying to write a small batch script that will delete files old files
I'm trying to write a script that will hidden/show div depending on other elements
I am trying to write a powershell script that will set a download directory
I'm trying to write a script that will create a user in MediaWiki, so

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.