Asked by:
command to get the file names from a txt file

General discussion
-
Hi
I have a txt file with the complete list of files and folders from the share folder.I would lilke to use powershell to extract the folder names out of this
File names are which ends with .xxx or .xx (eg: abc.txt ,abc.pl etc )
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2sea.dll
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2sec.dll
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2sem.dll
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2sexp.dll
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2six.dll
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2spi.dll
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2sms.dll
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2sne.dll
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2slk.dll
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2srl.dll
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2ss10.dll
p:\Apps\Program Files\Common Files\2.0\bin\crdb_p2strk.dll
p:\Apps\Program Files\Common Files\2.0
p:\Apps\Reports\OPPCPT.FP
p:\Apps\Reports\ORGTE.FP
p:\Apps\Reports\OTH43.FP
p:\Apps\Reports\
I am expecting an output as below
p:\Apps\Program Files\Common Files\2.0\
p:\Apps\Reports\
-Sachin
- Moved by Bill_Stewart Thursday, July 14, 2016 3:32 PM Unanswerable drive-by question
Wednesday, May 18, 2016 1:01 PM
All replies
-
Hi,
You forgot to post your script and ask your question.
Please read this to set your expectations of this forum:
Wednesday, May 18, 2016 1:21 PM -
Hi
Sorry I am new with Scripting I am using the below script to do this
get-content .\T_Drive.txt |Where-Object {( -notmatch '.dll')-and ( -notmatch '.FP') } |set-content outT.txt
But here I have to add each and every extensions in the Where-object part.Can someone please help to put a generic command line which will help me removing all lines with file extensions on 3 or 2 characters.
Wednesday, May 18, 2016 1:36 PM -
Start with help. It is always the first place to look for answers.
help help
help get-content -full
\_(ツ)_/
Wednesday, May 18, 2016 2:17 PM -
You can use wildcards for something like this:
Get-Content .\fileList.txt | Where { $_ -notlike '*.??' -and $_ -notlike '*.???' }
http://ss64.com/ps/syntax-wildcards.html
Wednesday, May 18, 2016 2:47 PM