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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
data808
Posts: 47
Joined: 19 Jul 2012 01:49

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

#1 Post by data808 » 29 Sep 2022 14:50

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

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

#2 Post by aGerman » 29 Sep 2022 15:40

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

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

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

#3 Post by Aacini » 29 Sep 2022 17:00

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

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

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

#4 Post by Aacini » 29 Sep 2022 17:08

However, if you want to move files (instead of highlight they), just enter this command:

Code: Select all

move *21.xls anotherFolder
:(

data808
Posts: 47
Joined: 19 Jul 2012 01:49

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

#5 Post by data808 » 29 Sep 2022 20:01

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.

data808
Posts: 47
Joined: 19 Jul 2012 01:49

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

#6 Post by data808 » 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.

miskox
Posts: 553
Joined: 28 Jun 2010 03:46

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

#7 Post by miskox » 29 Sep 2022 23:39

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

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

#8 Post by aGerman » 30 Sep 2022 00:28

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

data808
Posts: 47
Joined: 19 Jul 2012 01:49

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

#9 Post by data808 » 30 Sep 2022 19:04

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.

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

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

#10 Post by ShadowThief » 30 Sep 2022 21:54

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

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

#11 Post by aGerman » 01 Oct 2022 04:46

%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

Post Reply