Hello there! This is my first post here, so please apologize if I do not act strictly on forum rules.
I hope you can help!
What I'm trying to achieve:
I am creating a script that allows users tu enter three different variables (number="job number"; customer="Customer Name" and job="job description", that would later create a user path within a specific folder (%number%_%customer%_%job%). That part is easy.
However, what i can not achieve is cross checking if a folder already exists, based solely on the jobnumber.
What the script should do is check if an entered jobnumer is already in use within the destination folder. If so, it should open the existing folder(s) in explorer. There might be more than one with the same number (e.g. our dummy jobs all start with "000000").
Here is the simplified part of the script that should check whether there are already folders starting with the same number:
______________________________________________________
@echo off
set /p number="job number: "
set "folderExist="
for %%a in ("U:\destination\work in progress\%number%*") do set "folderExist=1" & goto continue
:continue
IF DEFINED folderExist (
start "" "U:\destination\work in progress\\%number%*"
) ELSE (
.... do something else ....
)
______________________________________________________
The asterisk as a wildcard is not recognised.
I hope you understand what I am trying to achieve here and that someone can assist me. Any help yould be greatly appreciated.
Best regards,
Andreas
P.S. Please note, that the destination folder is on a mapped network drive. I'm not sure if that makes any difference.
Adding Wildcards to variables
Moderator: DosItHelp
Re: Adding Wildcards to variables
I suggest you reread the help file for the IF command.
IF DEFINED checks if an environmental variable has any value assigned to it.
IF EXIST checks if a file or folder exists.
IF DEFINED checks if an environmental variable has any value assigned to it.
IF EXIST checks if a file or folder exists.
Re: Adding Wildcards to variables
The outcome is the same if I use "if exist", i tried that previously. Problem is, that after the variable %number% I am unable to use a wildcard to have the rest of the foldername ignored and open every folder that stards with a value that is equal to the entered %number%.
Re: Adding Wildcards to variables
Instead of FOR-FILES command, try directly
IF EXIST "U:\destination\work in progress\%number%*" do (....)
Re: Adding Wildcards to variables
Use the FOR command to your advantage.
Code: Select all
@echo off
set /p "number=job number: "
set "folderExist="
for /D %%G in ("U:\destination\work in progress\%number%*") do (
start "" "%%~G"
set "folderExist=Y"
)
IF NOT DEFINED folderExist (
.... do something else ....
)
Re: Adding Wildcards to variables
WOW Squashman, that does exactly what I need! Thank you very very much!!!