Search code examples
filebatch-filecopylowercase

batch script to copy lowercase file


I have files being uploaded to a folder. I need a batch script to redirect those files to separate folders based on filenames. That's all fine except for two sets of files that have very similar names but only different by case. Ie. log0000.txt and LOG0000.txt.

What I would like to do is search through the folder and check all files and if they have a lowercase "log", move them to one folder and if they have uppercase "LOG", move them to the other.

I know how to loop through the files in the folder, but I'm unsure how to match the comparision and match each file based on case.

Thanks.


Solution

  • Since you already know how to loop and move,

    @echo off
    
    for /f "usebackq delims=" %%f in (`dir /s /b log* ^| findstr "log"`) do (
        @rem code to copy all lower case files
    )
    
    for /f "usebackq delims=" %%f in (`dir /s /b log* ^| findstr "LOG"`) do (
        @rem code to copy all upper case files
    )