Page 1 of 1

Batch File To Highlight All Files In Folder with Specific File Name

Posted: 29 Sep 2022 14:50
by data808
Was wondering if someone could help me make a batch file that can highlight all files in a specific folder on my desktop that will highlight all files that have a file name that end with 21. Basically the 21 is representing the year and so the 2021 files are mixed in with the 2020 files. An example of the file names are like this:

083120.xls
083121.xls
090120.xls
090121.xls

etc.....

After the 2021 files are highlighted I plan to move them to another folder.

Re: Batch File To Highlight All Files In Folder with Specific File Name

Posted: 29 Sep 2022 15:40
by aGerman
Batch does not interact with graphical interfaces. So, no you can't highlight / mark files in an explorer list view. However, you can selectively move files.

Code: Select all

md "files 2021"
move "*21.*" "files 2021\"
FWIW: Having the order of the date YYMMDD rather than MMDDYY in your file names would probably help in future :wink:

Steffen

Re: Batch File To Highlight All Files In Folder with Specific File Name

Posted: 29 Sep 2022 17:00
by Aacini
The Batch file posted at this link does exactly what you requested: "Highlight All Files In Folder with Specific File Name":

Image

It just be necessary to slightly modify the Batch file in order to highligth the files that ends in "21" before the extension...

Antonio

Re: Batch File To Highlight All Files In Folder with Specific File Name

Posted: 29 Sep 2022 17:08
by Aacini
However, if you want to move files (instead of highlight they), just enter this command:

Code: Select all

move *21.xls anotherFolder
:(

Re: Batch File To Highlight All Files In Folder with Specific File Name

Posted: 29 Sep 2022 20:01
by data808
Thanks for the suggestions. I am very new to creating batch files and would probably need a completed code just to see how it all works. Would you be able to help with that if I gave more details of where the folder is and such?

Directory of the mixed files are here:

C:\Users\john.smith\Desktop\Test For Batch File

And directory of where I want to move the files to is here:

C:\Users\john.smith\Desktop\Destination Folder

Again, file names are in this format MMDDYY.xls with some even MMDDYYYY.xls so moving files ending with 21.xls should be ok since no matter which format they named the file in, it will still end with 21 either way and fit this scenario.

Thanks so much for the help.

Re: Batch File To Highlight All Files In Folder with Specific File Name

Posted: 29 Sep 2022 20:02
by data808
Oh and the reason I liked the highlight idea is so then I can see which files are selected before I drag them to the 2021 folder to make sure its functioning correctly. Thanks.

Re: Batch File To Highlight All Files In Folder with Specific File Name

Posted: 29 Sep 2022 23:39
by miskox
data808 wrote:
29 Sep 2022 20:02
Oh and the reason I liked the highlight idea is so then I can see which files are selected before I drag them to the 2021 folder to make sure its functioning correctly. Thanks.
Maybe there is no need to highlight them - just make sure you move them to empty folder. And there you will use

Code: Select all

dir *.21.xls*
and in source folder too (here should be zero files found).

Saso

Re: Batch File To Highlight All Files In Folder with Specific File Name

Posted: 30 Sep 2022 00:28
by aGerman
Would you be able to help with that if I gave more details of where the folder is and such?

Code: Select all

@echo off
set "src=%userprofile%\Desktop\Test For Batch File"
set "dst=%userprofile%\Desktop\Destination Folder"

if not exist "%dst%\" md "%dst%"
move "%src%\*21.xls" "%dst%\"
Steffen

Re: Batch File To Highlight All Files In Folder with Specific File Name

Posted: 30 Sep 2022 19:04
by data808
Thanks.

Does the batch file need to be in the destination folder when I run it? Below is the code I am referring to.

@echo off
set "src=%userprofile%\Desktop\Test For Batch File"
set "dst=%userprofile%\Desktop\Destination Folder"

if not exist "%dst%\" md "%dst%"
move "%src%\*21.xls" "%dst%\"

Also does I need those % signs in the locations of the folders? Ultimately I was going to assign the directories to a network drive. Would that change anything in the way this code works?

Thanks.

Re: Batch File To Highlight All Files In Folder with Specific File Name

Posted: 30 Sep 2022 21:54
by ShadowThief
Both src and dst are the full paths to the folders, so the script can be anywhere you want. %variable% is how you reference variables in batch, so you have to use %src% and %dst% instead of src and dst. %userprofile% is a system variable that already exists, so you don't need to worry about that.

If these are on a network drive, you'll want to mount them to drive letters first.

Re: Batch File To Highlight All Files In Folder with Specific File Name

Posted: 01 Oct 2022 04:46
by aGerman
%userprofile% is a predefined environment variable. It expands to C:\users\<name of the currently logged on user> which is the first part of the paths you previously wrote.

Steffen