Batch File To Highlight All Files In Folder with Specific File Name
Moderator: DosItHelp
Batch File To Highlight All Files In Folder with Specific File Name
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.
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
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.
FWIW: Having the order of the date YYMMDD rather than MMDDYY in your file names would probably help in future
Steffen
Code: Select all
md "files 2021"
move "*21.*" "files 2021\"
Steffen
Re: Batch File To Highlight All Files In Folder with Specific File Name
The Batch file posted at this link does exactly what you requested: "Highlight All Files In Folder with Specific File Name":
It just be necessary to slightly modify the Batch file in order to highligth the files that ends in "21" before the extension...
Antonio
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
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
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.
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
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
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*
Saso
Re: Batch File To Highlight All Files In Folder with Specific File Name
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%\"
Re: Batch File To Highlight All Files In Folder with Specific File Name
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.
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.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Batch File To Highlight All Files In Folder with Specific File Name
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.
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
%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
Steffen