Solved

newest file name in a directory

Posted on 2012-03-14
2
554 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now