Solved

newest file name in a directory

Posted on 2012-03-14
2
567 Views
Last Modified: 2012-03-14
Hi,

I am preparing a script with Powershell.

I'd like to get the newest file name in a directory and assign the name to a string variable.

I've just written this one. I have a question:

 dir  C:\PREPARACION\logs | sort -prop LastWriteTime | select -last 1

output:


Mode                LastWriteTime     Length Name                                                                                                                          
-a---          9/6/2011  11:38 PM     442200 aswSnx.sys


However, what I want is to assign "aswSnx.sys" file name to a string.

Any advice?

Thanks in advance
0
Comment
Question by:projectja
2 Comments
 
LVL 2

Accepted Solution

by:
SieQ earned 155 total points
ID: 37721736
$a =  (dir  C:\PREPARACION\logs | sort -prop LastWriteTime | select -last 1).Fullname
or
$a =  (dir  C:\PREPARACION\logs | sort -prop LastWriteTime | select -last 1).name
depends on what you want
0
 

Author Closing Comment

by:projectja
ID: 37721950
thanks guy. It is very useful
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Output to HTML in powershell 3 27
Powershell v3 - SQLCMD 3 27
Link failure 16 35
Creating accounts AD 2k8 PowerShell - Carriage Return in addresses 5 28
Utilizing an array to gracefully append to a list of EmailAddresses
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question