none
@FINDSTR - How to find an element containing . (dot) when . (dot) is wildcharacter RRS feed

  • Question

  • I'm checking a LogFile containing FileName(s) and want to Include/Exclude files according to FileType.

    How to use @FINDSTR  to find an element containing . (dot) when . (dot) is wildcharacter...???

    Thursday, August 14, 2014 7:22 AM

Answers


  • In the Powershell console and from the current folder (C:\) this command will put the results into a file C:\Music.txt (some access denied errors bleeded onto the screen)

    ${C:\Music.txt}=Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force

    Here is a portion of C:\Music.txt (This took about 4 minutes on my slow computer)

    C:\Program Files\Windows Photo Gallery\ChangeMetadata.wav
    C:\Program Files (x86)\iTunes\iTunes.Resources\axloadcomplete.wav
    C:\Program Files (x86)\iTunes\iTunes.Resources\complete.wav
    C:\Program Files (x86)\Microsoft Office\MEDIA\CAGCAT10\ELPHRG01.WAV
    C:\Program Files (x86)\Microsoft Office\MEDIA\CAGCAT10\J0214098.WAV
    C:\Program Files (x86)\Microsoft Office\Office12\MEDIA\APPLAUSE.WAV
    C:\Program Files (x86)\Microsoft Office\Office12\MEDIA\ARROW.WAV
    

    to run from the cmd prompt 

    powershell -command ${C:\Music.txt}=Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force

    • Marked as answer by TheCKruse Friday, August 15, 2014 1:42 AM
    Friday, August 15, 2014 12:16 AM
  • I use the following statement :

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force >"[AllFileList] # Music (Artists).txt"

    The result is NOT delivered in the format of 1 line for each item.

    I have tried :

    @PowerShell $a = Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force >"[AllFileList] # Music (Artists).txt"

    After 60 minutes there is still no result.... Hanging.....?????

    Then.....

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force | Format-Wide -AutoSize >"[AllFileList] # Music (Artists).txt"

    and

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force | Format-List >"[AllFileList] # Music (Artists).txt"

    Both give the same result: ABORT

    ..... Someone tell me what I do wrong.... I'm  new with PowerShell (this is the first time...)

    Why do you insist on putting an "@" in front of everything?

    Here is a workable command.  DON'T add an @ to it.

    REM run a powershell command
    PowerShell -command Get-ChildItem -Path c:\scripts\* -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wma >filelist.txt



    ¯\_(ツ)_/¯


    • Edited by jrv Friday, August 15, 2014 1:08 AM
    • Marked as answer by TheCKruse Friday, August 15, 2014 1:42 AM
    Friday, August 15, 2014 1:05 AM

  • In the Powershell console and from the current folder (C:\) this command will put the results into a file C:\Music.txt (some access denied errors bleeded onto the screen)

    ${C:\Music.txt}=Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force

    Here is a portion of C:\Music.txt (This took about 4 minutes on my slow computer)

    C:\Program Files\Windows Photo Gallery\ChangeMetadata.wav
    C:\Program Files (x86)\iTunes\iTunes.Resources\axloadcomplete.wav
    C:\Program Files (x86)\iTunes\iTunes.Resources\complete.wav
    C:\Program Files (x86)\Microsoft Office\MEDIA\CAGCAT10\ELPHRG01.WAV
    C:\Program Files (x86)\Microsoft Office\MEDIA\CAGCAT10\J0214098.WAV
    C:\Program Files (x86)\Microsoft Office\Office12\MEDIA\APPLAUSE.WAV
    C:\Program Files (x86)\Microsoft Office\Office12\MEDIA\ARROW.WAV
    

    to run from the cmd prompt 

    powershell -command ${C:\Music.txt}=Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force

    Brian,  nothing you are posting works as you think it does.


    ¯\_(ツ)_/¯

    • Marked as answer by TheCKruse Friday, August 15, 2014 1:41 AM
    Friday, August 15, 2014 1:10 AM
  • Now the original question was - "How to find lines in a file that match a file extension pattern"

    Get-Content c:\music.txt |Select-String '\.wav|\.mp3|\.mpg'


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, August 15, 2014 1:22 AM
    • Marked as answer by TheCKruse Friday, August 15, 2014 1:41 AM
    Friday, August 15, 2014 1:22 AM
  • type c:\music.txt | FINDSTR "[\.wav|\.mp3|\.mpg]"

    ¯\_(ツ)_/¯

    • Marked as answer by TheCKruse Friday, August 15, 2014 1:41 AM
    Friday, August 15, 2014 1:26 AM
  • Hello Everybody!

    I thank You all for the commitment in my "problem". I have learned a lot of New Things during the process.

    Personally I'm an old "IT-Professional" retired in 2005, and I hope You all forgive me for my stupid questions!

    (As far as I can see, the PowerShell was "released" in 2009, that's maybe the reason why it's new to me).

    ... TheCKruse

    • Marked as answer by TheCKruse Friday, August 15, 2014 1:51 AM
    Friday, August 15, 2014 1:51 AM
  • By the way...

    PowerShell -command Get-ChildItem -Path c:\scripts\* -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wma >filelist.txt

    give the same result as

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force >FileList.txt

    without echo on the screen... (that's why I use the '@' when running from batch-file)...

    • Marked as answer by TheCKruse Friday, August 15, 2014 2:31 AM
    Friday, August 15, 2014 2:30 AM
  • Get-Content c:\music.txt |Select-String '\.wav|\.mp3|\.mpg'

    I tried that and it worked great, it was fast. .mpg wasn't in the original get-childitem.

    Do the same thing again:

    ${c:\FilteredMusic.txt} = Get-Content c:\music.txt |Select-String '\.wav|\.mp3|\.mpg'

    or on the cmd line

    powershell -command ${c:\FilteredMusic.txt} = Get-Content c:\music.txt |Select-String '\.wav|\.mp3|\.mpg'

    $ indicates a variable in powershell similar to %variable% in the dos world.

    ${FileName} is telling powershell it's variable that's stored in a file rather than memory. ${UNC} works as well.

    ${Filename} works on both sides of the = sign and behaves like any "normal" Powershell variable. 

    • Marked as answer by TheCKruse Friday, August 15, 2014 9:16 AM
    Friday, August 15, 2014 6:51 AM

All replies

  • Your question makes no sense.

    What is @FINDSTR?  It is not a Windows command.

    In PowerShell

    Get-ChildItem c:\test\* =include *.pdf


    ¯\_(ツ)_/¯

    Thursday, August 14, 2014 7:30 AM
  • @FINDSTR is a function within @CMD.exe  (DOS emulator)...
    Thursday, August 14, 2014 7:36 AM
  • @FINDSTR an @XMD do not exist in Windows.  Where did you see these programs.

    THe "DOS" emulator has not exusted for years.  There is a console program called CMD.EXE which executes building and command line programs. 

    FINDSTR.EXE is a command line program that can be executed in CMD console or in the PowerShell Console.

    For instructions on how to use open a command prompt by clicking on the "command" program using "WinKey+R" and typing CMD.

    In the command window you can type CMD /? and FINDSTR /? to see how to use these programs.

    The "dot" character is not a wildcard character so it is not possible toknow wht you are asking.  FINDSTR uses a limited set of REGEX tokens where the dot is a wildcard match character.

    To match in  file you would need to use a regex supported by FINDSTR.

    If you are asking how to match the dot then you can use the escape '\' with the dot.


    ¯\_(ツ)_/¯

    • Proposed as answer by Mike Laughlin Thursday, August 14, 2014 3:30 PM
    Thursday, August 14, 2014 7:46 AM
  • Example:

    C:\scripts>echo hello|findstr "hello\."

    C:\scripts>echo hello.|findstr "hello\."
    hello.


    ¯\_(ツ)_/¯

    • Proposed as answer by jrv Thursday, August 14, 2014 4:26 PM
    Thursday, August 14, 2014 7:52 AM
  • @FINDSTR is a function within @CMD.exe (DOS emulator)...

    Just to clear up what appear to be multiple misunderstandings:

    Cmd.exe (no "@" character) is not a DOS emulator. It is a Win32 console application.

    Findstr.exe (also no "@" character) is another Win32 console application for finding strings. Findstr.exe is a separate program and is not a function within cmd.exe.


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Mike Laughlin Thursday, August 14, 2014 3:30 PM
    Thursday, August 14, 2014 2:17 PM
    Moderator
  • It is correct that I have explained the problem in a bad way, but still the problem remain...

    How to  use :

    FINDSTR /I /L ".mp3 .mp4 .m4a .ape .flac .cue .ogg" "LogFile.log" >"ListFile.log"

    when . [dot] is WildCharacter....?

    (I want a list of all audio files within a Directory/SubDirectries. I want to exclude .jpg, .ini, .png etc... My Archive contain more than 300 000 audio files and the system is using to much time "maintaining" those files. I have tried DIR /A-D *.<FileType> /-C /S /W /4 /ON >"ListFile.log", but the single run use about 25 minutes to process.)

    Thank You!

    Thursday, August 14, 2014 4:22 PM
  • Use PowerShell get-childitem. It has -include, -exclude, and -recurse.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by TheCKruse Thursday, August 14, 2014 7:00 PM
    • Unmarked as answer by TheCKruse Thursday, August 14, 2014 11:21 PM
    Thursday, August 14, 2014 6:00 PM
    Moderator
  • I use the following statement :

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force >"[AllFileList] # Music (Artists).txt"

    The result is NOT delivered in the format of 1 line for each item.

    I have tried :

    @PowerShell $a = Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force >"[AllFileList] # Music (Artists).txt"

    After 60 minutes there is still no result.... Hanging.....?????

    Then.....

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force | Format-Wide -AutoSize >"[AllFileList] # Music (Artists).txt"

    and

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force | Format-List >"[AllFileList] # Music (Artists).txt"

    Both give the same result: ABORT

    ..... Someone tell me what I do wrong.... I'm  new with PowerShell (this is the first time...)

    Thursday, August 14, 2014 11:20 PM

  • In the Powershell console and from the current folder (C:\) this command will put the results into a file C:\Music.txt (some access denied errors bleeded onto the screen)

    ${C:\Music.txt}=Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force

    Here is a portion of C:\Music.txt (This took about 4 minutes on my slow computer)

    C:\Program Files\Windows Photo Gallery\ChangeMetadata.wav
    C:\Program Files (x86)\iTunes\iTunes.Resources\axloadcomplete.wav
    C:\Program Files (x86)\iTunes\iTunes.Resources\complete.wav
    C:\Program Files (x86)\Microsoft Office\MEDIA\CAGCAT10\ELPHRG01.WAV
    C:\Program Files (x86)\Microsoft Office\MEDIA\CAGCAT10\J0214098.WAV
    C:\Program Files (x86)\Microsoft Office\Office12\MEDIA\APPLAUSE.WAV
    C:\Program Files (x86)\Microsoft Office\Office12\MEDIA\ARROW.WAV
    

    to run from the cmd prompt 

    powershell -command ${C:\Music.txt}=Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force

    • Marked as answer by TheCKruse Friday, August 15, 2014 1:42 AM
    Friday, August 15, 2014 12:16 AM
  • I use the following statement :

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force >"[AllFileList] # Music (Artists).txt"

    The result is NOT delivered in the format of 1 line for each item.

    I have tried :

    @PowerShell $a = Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force >"[AllFileList] # Music (Artists).txt"

    After 60 minutes there is still no result.... Hanging.....?????

    Then.....

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force | Format-Wide -AutoSize >"[AllFileList] # Music (Artists).txt"

    and

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force | Format-List >"[AllFileList] # Music (Artists).txt"

    Both give the same result: ABORT

    ..... Someone tell me what I do wrong.... I'm  new with PowerShell (this is the first time...)

    Why do you insist on putting an "@" in front of everything?

    Here is a workable command.  DON'T add an @ to it.

    REM run a powershell command
    PowerShell -command Get-ChildItem -Path c:\scripts\* -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wma >filelist.txt



    ¯\_(ツ)_/¯


    • Edited by jrv Friday, August 15, 2014 1:08 AM
    • Marked as answer by TheCKruse Friday, August 15, 2014 1:42 AM
    Friday, August 15, 2014 1:05 AM

  • In the Powershell console and from the current folder (C:\) this command will put the results into a file C:\Music.txt (some access denied errors bleeded onto the screen)

    ${C:\Music.txt}=Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force

    Here is a portion of C:\Music.txt (This took about 4 minutes on my slow computer)

    C:\Program Files\Windows Photo Gallery\ChangeMetadata.wav
    C:\Program Files (x86)\iTunes\iTunes.Resources\axloadcomplete.wav
    C:\Program Files (x86)\iTunes\iTunes.Resources\complete.wav
    C:\Program Files (x86)\Microsoft Office\MEDIA\CAGCAT10\ELPHRG01.WAV
    C:\Program Files (x86)\Microsoft Office\MEDIA\CAGCAT10\J0214098.WAV
    C:\Program Files (x86)\Microsoft Office\Office12\MEDIA\APPLAUSE.WAV
    C:\Program Files (x86)\Microsoft Office\Office12\MEDIA\ARROW.WAV
    

    to run from the cmd prompt 

    powershell -command ${C:\Music.txt}=Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force

    Brian,  nothing you are posting works as you think it does.


    ¯\_(ツ)_/¯

    • Marked as answer by TheCKruse Friday, August 15, 2014 1:41 AM
    Friday, August 15, 2014 1:10 AM
  • Now the original question was - "How to find lines in a file that match a file extension pattern"

    Get-Content c:\music.txt |Select-String '\.wav|\.mp3|\.mpg'


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, August 15, 2014 1:22 AM
    • Marked as answer by TheCKruse Friday, August 15, 2014 1:41 AM
    Friday, August 15, 2014 1:22 AM
  • type c:\music.txt | FINDSTR "[\.wav|\.mp3|\.mpg]"

    ¯\_(ツ)_/¯

    • Marked as answer by TheCKruse Friday, August 15, 2014 1:41 AM
    Friday, August 15, 2014 1:26 AM
  • Hello Everybody!

    I thank You all for the commitment in my "problem". I have learned a lot of New Things during the process.

    Personally I'm an old "IT-Professional" retired in 2005, and I hope You all forgive me for my stupid questions!

    (As far as I can see, the PowerShell was "released" in 2009, that's maybe the reason why it's new to me).

    ... TheCKruse

    • Marked as answer by TheCKruse Friday, August 15, 2014 1:51 AM
    Friday, August 15, 2014 1:51 AM

  • Brian,  nothing you are posting works as you think it does.


    ¯\_(ツ)_/¯

    Every time I attempt to answer a question, I am learning, some may not be have totally right, there's even been couple way out there in left field. But I know you guys are experts and will set things straight if need be. (thanks)

    I find it's cumulative, I find myself looking at previous posts to see how something was done and addressing the current issue expands my knowledge a little bit more.

    Tomorrow is my two-month anniversary of when I first heard of Powershell and took the Microsoft Virtual Academy powershell courses.

    Friday, August 15, 2014 2:18 AM
  • Hello Everybody!

    I thank You all for the commitment in my "problem". I have learned a lot of New Things during the process.

    Personally I'm an old "IT-Professional" retired in 2005, and I hope You all forgive me for my stupid questions!

    (As far as I can see, the PowerShell was "released" in 2009, that's maybe the reason why it's new to me).

    ... TheCKruse

    DOS was released before you were born and you still haven't learned what that is.  Be honest. You don't know how a computer works because you are an administrator.  When you get to be my age you will possibly understand how the ALU/RS works.  It was invented in 1954 or 5 by some college professor.  He stole the idea from Charles Babbage.

    DOS was created by IBM because they wanted to destroy the concept of small computers.  Long live Boca Raton - long live DARPA.


    ¯\_(ツ)_/¯

    Friday, August 15, 2014 2:24 AM

  • Brian,  nothing you are posting works as you think it does.


    ¯\_(ツ)_/¯

    Every time I attempt to answer a question, I am learning, some may not be have totally right, there's even been couple way out there in left field. But I know you guys are experts and will set things straight if need be. (thanks)

    I find it's cumulative, I find myself looking at previous posts to see how something was done and addressing the current issue expands my knowledge a little bit more.

    Tomorrow is my two-month anniversary of when I first heard of Powershell and took the Microsoft Virtual Academy powershell courses.

    Brian - you are learning.  Your method of loading a file is cute and different.  Next time read the whole question and you will likely nail it perfectly.

    Good going.  Stop counting anniversaries.  You are past that. 
    MSVA is pretty cool for getting started.  I like to encourage them.


    ¯\_(ツ)_/¯

    Friday, August 15, 2014 2:27 AM
  • By the way...

    PowerShell -command Get-ChildItem -Path c:\scripts\* -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wma >filelist.txt

    give the same result as

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force >FileList.txt

    without echo on the screen... (that's why I use the '@' when running from batch-file)...

    • Marked as answer by TheCKruse Friday, August 15, 2014 2:31 AM
    Friday, August 15, 2014 2:30 AM
  • By the way...

    PowerShell -command Get-ChildItem -Path c:\scripts\* -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wma >filelist.txt

    give the same result as

    @PowerShell Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force >FileList.txt

    without echo on the screen... (that's why I use the '@' when running from batch-file)...

    Oh - so you are admitting that the @ is not part of the command. 

    See.

    Even an old kid like you
    can learn something new. 
    Now it is time to see
    if you can be a scripter
    like me.  Or not. 

    But.
    That is a lot
    for a tot like you
    who likes to decorate
    all things blue with an 'at';
    "That" is new.

    PowerShell is not!


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, August 15, 2014 2:52 AM
    Friday, August 15, 2014 2:52 AM
  • As You told me

    @PowerShell ${"%MainDir%\%FullPath%\%FullFileName%"}=Get-ChildItem -Include *.mp3,*.mp4,*.m4a,*.flac,*.cue,*.ogg,*.ape,*.wav,*.wv -recurse -force

    used 64 minutes to finish...

    I'm running on

    OS-navn Microsoft Windows 7 Ultimate
    Versjon 6.1.7601 Service Pack 1 Build 7601
    Beskrivelse for annet OS  Ikke tilgjengelig
    OS-produsent Microsoft Corporation
    Systemnavn 
    Systemprodusent Micro-Star International Co., Ltd.
    Systemmodell GX780/GT780/GT780DX
    Systemtype x64-based PC
    Prosessor Intel(R) Core(TM) i7-2670QM CPU @ 2.20GHz, 2201 Mhz, 4 kjerne(r), 8 logiske prosessor(er)
    BIOS-versjon/-dato American Megatrends Inc. E1761IMS V1.0C, 09.09.2011
    SMBIOS-versjon 2.7
    Windows-mappe C:\Windows
    Systemmappe C:\Windows\system32
    Oppstartsenhet \Device\HarddiskVolume1
    Nasjonal innstilling Norge
    Hardware Abstraction Layer Versjon = "6.1.7601.17514"
    Brukernavn 
    Tidssone Vest-Europa (sommertid)
    Installert fysisk minne (RAM) 14,0 GB
    Fysisk minne totalt 14,0 GB
    Fysisk minne tilgjengelig 10,1 GB
    Virtuelt minne totalt 26,0 GB
    Virtuelt minne tilgjengelig 22,1 GB
    Plass for sidevekslingsfil 12,0 GB
    Sidevekslingsfil C:\pagefile.sys

    SystemDrive = SSD

    The data is stored on NAS (2.2TB AudioFiles)....

    The "FullFileName" (OutPut) is absolutely OK!!!

    Thank You a 1000 times!

    @TheCKruse

    Friday, August 15, 2014 5:19 AM
  • For ($I=0; $I -LT 1000; $I++)  {Write-Host "You're welcome"}

    Friday, August 15, 2014 5:34 AM
  • I'm still not totally finished...

    Get-Content c:\music.txt |Select-String '\.wav|\.mp3|\.mpg'

    As I understand c:\music.txt is the "OutputFile". Is there a "ListFile" or where do the statement find "TheSourceFile(s)...?

    I tried

    PowerShell Get-Content "%MainDir%\%FullPath%\%ListFileName%" |Select-String '\.mp3|\.mp4|\.m4a|\.flac|\.cue|\.ogg|\.ape|\.wav|\.wv' >"%FullFileName%"

    and it ABORTED...

    In this statement I used "C:\Music.txt" as an "InputFileList"

    I'm running batch-jobs, so it has to be an "OutputFile", not the consol...


    • Edited by TheCKruse Friday, August 15, 2014 6:15 AM
    Friday, August 15, 2014 6:15 AM
  • Get-Content c:\music.txt |Select-String '\.wav|\.mp3|\.mpg'

    I tried that and it worked great, it was fast. .mpg wasn't in the original get-childitem.

    Do the same thing again:

    ${c:\FilteredMusic.txt} = Get-Content c:\music.txt |Select-String '\.wav|\.mp3|\.mpg'

    or on the cmd line

    powershell -command ${c:\FilteredMusic.txt} = Get-Content c:\music.txt |Select-String '\.wav|\.mp3|\.mpg'

    $ indicates a variable in powershell similar to %variable% in the dos world.

    ${FileName} is telling powershell it's variable that's stored in a file rather than memory. ${UNC} works as well.

    ${Filename} works on both sides of the = sign and behaves like any "normal" Powershell variable. 

    • Marked as answer by TheCKruse Friday, August 15, 2014 9:16 AM
    Friday, August 15, 2014 6:51 AM
  • The "PowerShellDummy" still living...

    I've tried

    PowerShell ${"%MainDir%\%FullPath%\%FullFileName%"} = Get-Content ${"%MainDir%\%FullPath%\%ListFileName%"} |Select-String '\.mp3|\.mp4|\.m4a|\.flac|\.cue|\.ogg|\.ape|\.wav|\.wv'

    where "%MainDir%\%FullPath%\%ListFileName%" is result of a @DIR  *.* command outside PowerShell

    The PowerShell statment ABORT without any Message (I've removed the @ to get onscreen Message(s)

    Can I use ${....} twice in the same statement.... (as I have done) or do I have to $a and $b....?

    Friday, August 15, 2014 10:05 AM
  • The "PowerShellDummy" still living...

    I've tried

    PowerShell ${"%MainDir%\%FullPath%\%FullFileName%"} = Get-Content ${"%MainDir%\%FullPath%\%ListFileName%"} |Select-String '\.mp3|\.mp4|\.m4a|\.flac|\.cue|\.ogg|\.ape|\.wav|\.wv'

    where "%MainDir%\%FullPath%\%ListFileName%" is result of a @DIR  *.* command outside PowerShell

    The PowerShell statment ABORT without any Message (I've removed the @ to get onscreen Message(s)

    Can I use ${....} twice in the same statement.... (as I have done) or do I have to $a and $b....?

    I am going to recommend that you choose either CMD or PowerShell and stick to that shell system.  You know almost nothing bout either of them and by trying to mic them you are just getting more and more confused.

    You are trying to say that the CMD variables - the ones in % signs - are the result of a "dir *.*" command.  They are not.  Also note that, as I posted before, the @ sign does NOT suppress output.  It only suppresses the echoing of the command and is used inside of batch files to suppress output of the command string.  We normally place an @echo off at the beginning of a batch file and all echoing I suppressed.

    PowerShell has none of these issues.  It is more flexible and works without any old batch.  Just start PowerShell by typing WinKey+R and type powershell.  From that point test your theories but stick to PowerShell.

    Start here: http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

    It takes about 4 to 8 hours with the training materials to catch on to how PowerShell works.  Good luck.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, August 15, 2014 10:33 AM
    Friday, August 15, 2014 10:33 AM
  • In PowerShell this is how it would normally be done:

    $listfile='c:\somepath\listfile.txt'
    $outfile='c:\somepath\outfile.txt'
    
    Get-Content $listfile |
         Select-String '\.mp3|\.mp4|\.m4a|\.flac|\.cue|\.ogg|\.ape|\.wav|\.wv' |
         Out-File $outfile

    This can be easily placed in a file and executed.  There is no need for mixing shells,


    ¯\_(ツ)_/¯

    Friday, August 15, 2014 10:39 AM
  • The function I'm making is only a SubRoutine in a large BatchFile. The different "%<Variables>%" is changed during RunTime.

    The total BatchFile is some 1000 lines long... It will take to long time to re-Write everything to PowerShell.

    "%MainDir%\%FullPath%\%FullFileName%" = M:\Music\FileName.txt

    "%MainDir%\%FullPath%\%ListFileName%" = M:\Music\FileName.log

    all of these "%<variables>%" are ChangeAble

    I have an Archive containing more than 300.000 audiofiles. These audiofiles are stored in a structure to make it possible to maintain and update.

    The structure is dynamic and I don't want to re-Write the code everytime the structure is changed

    I don't have control of the changes, that's why the code itself has to be dynamic.


    • Edited by TheCKruse Friday, August 15, 2014 2:45 PM
    Friday, August 15, 2014 11:34 AM
  • YOu are do what no tech should ever do. YOu are saying that ther eis only one way to do what you want and you will force everything through that limited filter.

    PowerShell, in many cases, can replace 100 lines of a bath file with one line.

    Part of the issue is that you do not understand batch script and cannot understand any of the answers given to you that answer your original question. We gave you the batch only answer. YOu didn't even try it.

    1000+ lines to maintain a few media files is a bit crazy.  You could more easly maintain 5 or 100 lines of PowerShell and also get help from thousands more people.  Why keep insisting on using something that you clearly do not understand or know how to use.

    Don't take offense.  I am just trying to show you that there is an easier way.  I have used batch, PowerShell and most other major languages for more than 40 years.  Us technicians sometimes have to learn a language over a weekend.  After the first one or wo the rest are easy.

    Batch will never teach you how to write a program.  It is a utility and not a programming language. It was never int3ended to be used the way you are using it and has not been used for more than trivial things for almost 20 years.  Batch went out when Windows NT was released.  Only people who like the challenge of doing the impossible like to use batch.

    Either use the FINDSTR solution or switch to learning PowerShell.

    Note that you asked one question which was marked as answered and now you are asking a new and completely different question.

    PS.  Batch files do not work easily with "dynamic" structures.  PowerShell was designed to address this and hundreds of other weaknesses.


    ¯\_(ツ)_/¯

    Friday, August 15, 2014 3:38 PM
  • I would add that this forum is really designed to answer specific scripting questions.

    It's not really within the scope of this forum to ask others to design a custom solution for you (particularly when you specify constraints such as "it must be a batch file").


    -- Bill Stewart [Bill_Stewart]

    Friday, August 15, 2014 4:12 PM
    Moderator
  • PowerShell ${"%MainDir%\%FullPath%\%FullFileName%"} = Get-Content ${"%MainDir%\%FullPath%\%ListFileName%"} |Select-String '\.mp3|\.mp4|\.m4a|\.flac|\.cue|\.ogg|\.ape|\.wav|\.wv'

    That wont work. Two things wrong

    First thing

    Get-Content expects a filename  like Get-Content c:\music.txt  

    or  Get-Content "%MainDir%\%FullPath%\%ListFileName%"  

    Get-Content ${c:\music.txt} will try to get the filename in the file c:\music.txt and not use c:\music.txt itself.

    Second Thing

    ${"%MainDir%\%FullPath%\%FullFileName%"} = is wrong, don't use the " inside the { }, the { } act as a quotes

    for example ${C:\My Documents\Music.txt} = is ok, that will work, this is a variable

    PowerShell ${"%MainDir%\%FullPath%\%FullFileName%"} = Get-Content ${"%MainDir%\%FullPath%\%ListFileName%"} |Select-String '\.mp3|\.mp4|\.m4a|\.flac|\.cue|\.ogg|\.ape|\.wav|\.wv'

    Should be 

    PowerShell ${%MainDir%\%FullPath%\%FullFileName%} = Get-Content "%MainDir%\%FullPath%\%ListFileName%" |Select-String '\.mp3|\.mp4|\.m4a|\.flac|\.cue|\.ogg|\.ape|\.wav|\.wv'



    Friday, August 15, 2014 4:39 PM
  • While Brian's technique is cute it presents many problems for the transfer of data to PowerShell.

    This is how most of us would do this because it does not rely on the CMD shell to cooperate.

    Set  FileTOProcess=%Maindir%\%FullPath%\%ListFileName%
    Set OutputFile=%MainDir%\%FullPath%\%FullFileName%
    PowerShell -command "Get-Content $env:FileToProcess |Select-String '\.txt|\.mp3|\.mp4|\.m4a|\.fac|\.cue|\.ogg\.ape|\.wav|\.wv'| Out-File $env:OutpuFile"
    


    ¯\_(ツ)_/¯

    Friday, August 15, 2014 6:28 PM
  • # place this in a file
    #Select-ByExtension.ps1
    Get-Content $args[0] |
         Select-String '\.txt|\.mp3|\.mp4|\.m4a|\.fac|\.cue|\.ogg\.ape|\.wav|\.wv'| 
         Out-File $args[1]
    # end of file
    
    REM execute this in teh batch file.
    Powershell -File Select-ByExtension.ps1 -Arguments %Maindir%\%FullPath%\%ListFileName%,%MainDir%\%FullPath%\%FullFileName%


    ¯\_(ツ)_/¯

    Friday, August 15, 2014 6:31 PM
  • While Brian's technique is cute it presents many problems for the transfer of data to PowerShell.

    This is how most of us would do this because it does not rely on the CMD shell to cooperate.

    
    

    ¯\_(ツ)_/¯

    LOL, It's not my technique, I did not make it up nor implement it. It is a feature of Powershell that is available and works. I learnt it from Jeffery Snover (inventor and chief architect of Powershell)

    At the 22:30 mark of Module 7, he talks about the "squiggy brackets"

    Microsoft Virtual Academy

    Getting Started with PowerShell 3.0 Jump Start
    http://www.microsoftvirtualacademy.com/training-courses/getting-started-with-powershell-3-0-jump-start

    Module 7 - Getting prepared for automation
    http://www.microsoftvirtualacademy.com/Content/ViewContent.aspx?et=3286&m=3282&ct=17858



    I did the course two months ago today, back then a lot went over my head. I watched it over again about week ago and picked up lot that I missed the first time. This was one of those things.

    I did not realize it presented problems for the transfer of data to PowerShell,; nothing is being transferring anything to Powershell, it is occurring within Powershell with features it provides.

    I thought that was is why the "powershell  -command" option was provided so scripts wasn't needed to take of advantage of some feature in Powershell being called from a batch file.

    It easier to maintain 1 file and I am believer in freedom of expression.



    Friday, August 15, 2014 9:40 PM