Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, April 18, 2016 4:22 PM
Hello,
I am using the dir command to list multimedia files on our storage server in the following format:
dir /s \server_name_and_path\.jpg *.mp3 *.avi > \path_to_output_file\Report.txt
It works, but it only matches the first file type specified, in this case "jpg". I looked online for the proper syntax, but no matter how I separate the file types or move the "/s" switch around it always only matches the first file type specified. I tried using "*.jpg,*.mp3,*.avi" and "*.jpg;*.mp3;*.avi" but it didn't help.
What am I doing wrong here?
I know I can get this done using PowerShell or many other tools, but I am trying to understand how dir works and what I am doing wrong. My goal is to have a list of specified multimedia files within a specific directory.
I am running this on Windows Server 2012 Standard, x64.
Thank you for your help.
All replies (11)
Monday, April 18, 2016 5:01 PM âś…Answered | 2 votes
Good Day
I really dont know how DIR works when trying to get specific file extension
But i do know how to do it in powershell
$Extensions = '*.jpg','*.mp3','*.avi'
$src = "\\servername_and_path"
Get-ChildItem $src -Include $Extensions -Recurse -Force | Export-CSV "\\path_to_outputfile\file.csv" -NoTypeInformation
Hope this works
Regards
Monday, April 18, 2016 5:26 PM
Hello,
Alvaro's suggestion is good. Standard dir command won't be able to perform your search as a simple one-liner. You can write a script with three lines:
dir /s \\server_name_and_path\*.jpg > \\path_to_output_file\Report.txt
dir /s \\server_name_and_path\*.mp3 >> \\path_to_output_file\Report.txt
dir /s \\server_name_and_path\*.avi >> \\path_to_output_file\Report.txt
However, it's a worse solution that Alvaro's one.
Monday, April 18, 2016 6:10 PM
Thank you Alvaro. I appreciate your help and quick response.
Monday, April 18, 2016 6:13 PM
Robert, is this new in Windows Server 2012? I remember I used to be able to do this in older version of Windows.
In terms of efficiency, is the CMD script or the PowerShell script more efficient? I am going over approximately 1.5 TB of data.
Thank you.
Monday, April 18, 2016 6:35 PM
I have never compared the performance of Powershell cmdlets and command line tools. Powershell is more flexible, is included in all modern Microsoft products and has a lot of other great features so it is recommended to learn and use it. Especially, if you have Windows 2012 that fully supports Powershell.
"Robert, is this new in Windows Server 2012? I remember I used to be able to do this in older version of Windows."
As far as I know, your line shouldn't work in in older versions of Windows. The line "dir /s \server_name_and_path\.jpg *.mp3 *.avi" do the following:
1. Lists all .jpg files on the network share recursively.
2. Then lists all .mp3 files for the current working path recursively.
3. Then do the same as in "2" for .avi files.
So, the steps "2" and "3" don't search your network share. They use the local path.
Monday, April 18, 2016 6:51 PM
You are right. PowerShell is more flexible and supports more features. It is most definitely worth learning.
I just remembered that I used this tool in the past and it worked as a one line command. This was back in the Win Server 2003 days.
Follow up question:
Is there a way to have the PS script search for all listed file extensions at the same time per folder?
I have Alvarado's script running on a smaller sample of data, and it works, but it searches only for *.jpg first, then it goes back for *.mp3 and so on.
This would make the output file much easier to search per user.
Alvarado's script:
$Extensions = '*.jpg','*.mp3','*.avi'
$src = "\\servername_and_path"
Get-ChildItem $src -Include $Extensions -Recurse -Force | out-file \\path_to_output_file
Monday, April 18, 2016 7:25 PM
Sorry i forgot to add the output file
you can use the Out-File for a txt file as you mentioned before
Or you can use Export-Csv -NoTypeInformation to export the info to a CSV file
Im adding that to my first comment
Regards
Monday, April 18, 2016 7:32 PM
Thanks. I think CSV might be more useful for later processing.
Monday, April 18, 2016 7:37 PM
Ok i updated my first comment using Export-CSV
Regards
Monday, April 18, 2016 7:45 PM
I just reviewed the output file and Alvarado's script works perfectly. I thought that it was only searching for one extension at a time, but those folders at the beginning of the output file only had jpg files to begin with so it didn't list anything else.
Other folders throughout the output file list files with mp3, jpg and avi file extensions.
I guess I will have to focus on PowerShell a bit more.
Thank you guys for your help.
Monday, April 18, 2016 7:49 PM
Glad it worked
Dont forget to mark my code as an answer
Regards