Solved - Change output format

GDay All,

I’m new here and new to PowerShell.

I need to list files that are NOT .mp4 in multiple folders and then output those path/filenames to a text file.

I am using this command:

get-childitem N:\ -recurse | where-object { $_.Extension -notlike '*mp4' } | Out-File files.txt

I call this .ps1 script from a .bat file and so far it works well. The output is nice, but not quite what I desire. There is a lot of information about the folders (type, date created, etc.) and that is not really needed in this case.

I would like to see output something more like this, where it simply lists the path/filename of any file that is NOT an .mp4:

N:\Folder\filename.xxx
N:\Folder\Folder\filename.xxx

If it matters, I am using Windows 11 Pro.

Any help or suggestions would be greatly appreciated.

I think you need to “select” what you need and format selection, ex:

Get-ChildItem N:\ -Recurse -Filter "*.mp4" | Select-Object -Property Name, Fullname | Format-List | Out-File files.txt

EDIT:
I deleted my previous post but didn’t see I can edit again :frowning:

@metablaster

Thanks for the reply.

Your solution has helped, but it still lists the folders that only contain .mp4 files separate to the path/filename (fullname).

Property=name is not needed and fullname gives the desired path/filename, so I am a step closer to the perfect solution, thanks :slight_smile:

The command now looks like:

get-childitem N:\ -recurse | where-object { $_.Extension -notlike '*mp4' } | Select-Object -Property Fullname | Format-List | Out-File files.txt

I just need to remove the folder listings that have only .mp4 files and no other files in them now.

Any idea how I can select for that?

First, set up some folders that are small, but have some data to work with making tests easier.

Something like

PS F:\> Get-ChildItem -Recurse


    Directory: F:\


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        11/16/2022   7:58 PM                parentDirectory


    Directory: F:\parentDirectory


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        11/16/2022   7:59 PM                childDirectory
-a----        11/16/2022   7:54 PM           6185 excelFile.xlsx
-a----        11/16/2022   7:53 PM              0 mediaFile.mp4
-a----        11/16/2022   7:54 PM              0 Textfile.txt
-a----        11/16/2022   7:54 PM              0 wordDoc.docx


    Directory: F:\parentDirectory\childDirectory


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        11/16/2022   7:54 PM           6185 childExcelFile.xlsx
-a----        11/16/2022   7:53 PM              0 childMediaFile.mp4
-a----        11/16/2022   7:54 PM              0 childTextFile.txt
-a----        11/16/2022   7:54 PM              0 childWordFile.docx


PS F:\>

Now to get a return that does not include any file ending in mp4. You are going to kick your self for missing this in the docs. I know when I re read to refresh I smacked my forehead for not remembering this option.

Get-ChildItem -Recurse -Exclude *.mp4

Now run it

PS F:\> Get-ChildItem -Recurse -Exclude *.mp4


    Directory: F:\


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        11/16/2022   7:58 PM                parentDirectory


    Directory: F:\parentDirectory


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        11/16/2022   7:59 PM                childDirectory


    Directory: F:\parentDirectory\childDirectory


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        11/16/2022   7:54 PM           6185 childExcelFile.xlsx
-a----        11/16/2022   7:54 PM              0 childTextFile.txt
-a----        11/16/2022   7:54 PM              0 childWordFile.docx


    Directory: F:\parentDirectory


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        11/16/2022   7:54 PM           6185 excelFile.xlsx
-a----        11/16/2022   7:54 PM              0 Textfile.txt
-a----        11/16/2022   7:54 PM              0 wordDoc.docx


PS F:\>

Now to make it “pretty”

(Get-ChildItem -Recurse -Exclude *.mp4).fullname

now run it

PS F:\> (Get-ChildItem -Recurse -Exclude *.mp4).fullname
F:\parentDirectory
F:\parentDirectory\childDirectory
F:\parentDirectory\childDirectory\childExcelFile.xlsx
F:\parentDirectory\childDirectory\childTextFile.txt
F:\parentDirectory\childDirectory\childWordFile.docx
F:\parentDirectory\excelFile.xlsx
F:\parentDirectory\Textfile.txt
F:\parentDirectory\wordDoc.docx
PS F:\>

1 Like

@Matt

Thanks for the detailed reply, it is quite helpful.

The only advantage is that the command is shorter and some might say, more elegant … lol

That works, but no better than what I have already. It still lists folders that only contain .mp4 files, which means it outputs the path/foldername and nothing else, a good deal of the time.

E.G.

N:\TV Series
N:\TV Series\$#! My Dad Says
N:\TV Series\$#! My Dad Says\Season 01
N:\TV Series\11.22.63
N:\TV Series\11.22.63\Season 01
N:\TV Series\2 Broke Girls
N:\TV Series\2 Broke Girls\Season 01
N:\TV Series\2 Broke Girls\Season 02
N:\TV Series\2 Broke Girls\Season 03
N:\TV Series\2 Broke Girls\Season 04
N:\TV Series\2 Broke Girls\Season 05
N:\TV Series\2 Broke Girls\Season 06
N:\TV Series\A Bit Of Fry And Laurie
N:\TV Series\A Bit Of Fry And Laurie\Season 01
N:\TV Series\A Bit Of Fry And Laurie\Season 02
N:\TV Series\A Bit Of Fry And Laurie\Season 03
N:\TV Series\A Bit Of Fry And Laurie\Season 04
N:\TV Series\A Bit Of Fry And Laurie\Specials

Currently, I have less folder output than the above, E.G.:

FullName : N:\TV Series
FullName : N:\TV Test
FullName : N:\files.txt
FullName : N:\FindAll.bat
FullName : N:\FindAll.ps1
FullName : N:\TVDB ID's.txt
FullName : N:\TV Series\$#! My Dad Says
FullName : N:\TV Series\11.22.63
FullName : N:\TV Series\2 Broke Girls
FullName : N:\TV Series\A Bit Of Fry And Laurie

I need only the path/filename for files that are not .mp4:

FullName : N:\FindAll.bat
FullName : N:\FindAll.ps1
FullName : N:\TVDB ID's.txt

If you have any ideas on how to achieve that, I’m all ears … lol

You just need to add the -File parameter to exclude folders from the output:

(Get-ChildItem -Recurse -Exclude *.mp4 -File).FullName

Thanks @matt-bloomfield, that worked perfectly! :slight_smile:

Sorry, missed the detail about skipping folders.