Search code examples
command-linecommand-promptdirectory-listing

CMD dir List video files - Not Found error


I crafted some command line code (function? I don't know the technical term, my apologies) that is meant to look in a network folder (and all it's subfolders) and only list the file path for those files that are a particular type. I tried to test it on a folder with less information in it first, however I got the error File Not Found. This confused me because I looked in the folder--there were definitely .VOB and .mp4 files in the specified folder.

When I run the code included below, I don't get the error, BUT I'm getting a bunch of files I don't want (.pdf .xml .jpeg--etc.) I think because they're system files such as the .jpeg files for the .avi thumbnails.

dir "\\nas-rb4b\projectx2" /s /b *.avi *.mov *.mp4 *.wmv *.mpg *.lnk *.ldb *.rar *.mpeg *.m4v *.vob *.zip>Projx2RERUN.txt

Can anyone help me understand why I got the File Not Found error when I tried to run the exact same code but with a different more specific folder?

I also don't know how to modify the code/function to exclude files that are not the listed file types and are not system folders. Any help is, as always, much appreciated!


Solution

  • Read the newest dir command reference in Windows Commands:

    Syntax:

    dir [<Drive>:][<Path>][<FileName>] [...] [/p] [/q] [/w] [/d] [/a[[:]<Attributes>]][/o[[:]<SortOrder>]] [/t[[:]<TimeField>]] [/s] [/b] [/l] [/n] [/x] [/c] [/4]
    

    Remarks:

    To use multiple FileName parameters, separate each file name with a space, comma, or semicolon.

    The command in question dir "\\nas-rb4b\projectx2" /s /b *.avi *.mov *.mp4 (truncated) says and performs the following:

    • dir "\\nas-rb4b\projectx2" /s /b, (i.e. all files in "\\nas-rb4b\projectx2"), then
    • dir /s /b *.avi (i.e. all .avi files in the current directory), then
    • dir /s /b *.mov (i.e. all .mov files in the current directory), then
    • dir /s /b *.mp4 (i.e. all .mp4 files in the current directory), …

    Solution (read pushd and popd reference as well):

    pushd "\\nas-rb4b\projectx2"
    dir /s /b *.avi *.mov *.mp4 *.wmv *.mpg *.lnk *.ldb *.rar *.mpeg *.m4v *.vob *.zip>Projx2RERUN.txt
    popd