Solved AWildcard to ignore what is after the folder name to mk dir?

February 4, 2020 at 12:34:07
Specs: Windows 10
I have a question about 'wildcards' - I have a counter make directory 'Windows Command script' I made - the question - they want to rename and a 'job title' after the job number - (ie below_ - '20-0101' the counter works perfect for 20-0102, 20-0103, etc. But, if they add the job title 20-0102 -P&G Hand rail job - The script will create a 20-0102 folder again, instead of 20-0103 and so on.

Is there a way I can add a 'wildcard' in my script like:

@echo off
set counter=101
mkdir "20-0101***" 1>nul || goto :TryNext
To make it just look at the beginning part of the name for the counter (20-0101)

@echo off
set counter=101
mkdir "20-0101" 1>nul || goto :TryNext
:continue
REM rest of your code

goto :eof
:TryNext
set /a counter+=1
mkdir "20-0%counter%" 2>nul || goto :TryNext
mkdir "20-0%counter%\BOM & Shipping List"
mkdir "20-0%counter%\P.O"
mkdir "20-0%counter%\ProNest Outputs"
mkdir "20-0%counter%\Shipping"

goto :continue
Thanks in advance!


See More: AWildcard to ignore what is after the folder name to mk dir?


#1
February 5, 2020 at 02:06:23
Does the folder structure have to look something like this?(I am probably not understanding you well enough):

C:.
+---20-0101
|   +---BOM & Shipping List
|   +---P.O
|   +---ProNest Outputs
|   \---Shipping
+---20-0102
|   +---BOM & Shipping List
|   +---P.O
|   +---ProNest Outputs
|   \---Shipping
+---20-0103
|   +---BOM & Shipping List
|   +---P.O
|   +---ProNest Outputs
|   \---Shipping
+---20-0104
|   +---BOM & Shipping List
|   +---P.O
|   +---ProNest Outputs
|   \---Shipping
\---20-0105
    +---BOM & Shipping List
    +---P.O
    +---ProNest Outputs
    \---Shipping

code=

@echo off
for /l %%1 in (101,1,105) do (
	for /d %%a in ("BOM & Shipping List","P.O","ProNest Outputs","Shipping") do (
		mkdir "20-0%%1\%%~a"
	)
)

i5-6600K[delid]@4.8GHz Core/4.6 Cache@1.456v | 2x8GB DDR4-3200MHzCL12-12-12-28-1@1.5v | Sapphire Nitro+ SE RX 590 8GB@1610Mhz core@1.13v/2236MHz


Report •

#2
February 5, 2020 at 06:44:36
Thanks for your reply. Yes, that is it.. but if they rename the folder (which they want to add in the Job name after the #- i.e. 20-0101 - "Job Name") The script will then create the next folder to be 20-0101. I was wondering if there was a way to put a 'wildcard' in the script, to prevent it from making another folder, just because the folder ends with some different characters?

I hope this makes sense.
Thanks,
Russell


Report •

#3
February 5, 2020 at 12:37:03
✔ Best Answer
Fixed, you can rename it and run i again, it wont re-create a folder which was renamed

@echo off
for /l %%1 in (101,1,105) do (
	if not exist "20-0%%1*" (
		for /d %%a in ("BOM & Shipping List","P.O","ProNest Outputs","Shipping") do (
			mkdir "20-0%%1\%%~a"
		)
	)
)

i5-6600K[delid]@4.8GHz Core/4.6 Cache@1.456v | 2x8GB DDR4-3200MHzCL12-12-12-28-1@1.5v | Sapphire Nitro+ SE RX 590 8GB@1610Mhz core@1.13v/2236MHz


Report •

Related Solutions

#4
February 5, 2020 at 12:44:45
Thanks for your help!

Report •

Ask Question