Solved

newest file name in a directory

Posted on 2012-03-14
2
577 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

627 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