Page 1 of 1
find complete folder name based on first 4 characters?
Posted: 18 May 2012 12:47
by bridfi
im just trying to find a way to find the complete directory name based on the first 4 characters..
4224 asdjasd sd as das dsa dsa ds
4522 asdasdssadda
4676 asdasdasd sd ad s da
4899 asdasdssad sdasd sa
4902 asdasdsa sd asd a
etc....
if given "4899", and one folder matches, return the entire directory name
im trying to figure out a way to do a MOVE or a COPY with wildcards in the DESTINATION... can it be done??
for example...
copy 4899*.* 4899*
thanks in advance guys
Re: find complete folder name based on first 4 characters?
Posted: 18 May 2012 13:57
by aGerman
Not quite sure what exactly you're looking for.
Regards
aGerman
Re: find complete folder name based on first 4 characters?
Posted: 18 May 2012 15:14
by bridfi
thats perfect.. can i store the output as a variable to use as a destination for the move??
im just trying to move files into their respective folders.
all files will start with 5555
and folders start with 5555, 5556, etc..
thank you in advance!
Re: find complete folder name based on first 4 characters?
Posted: 18 May 2012 16:56
by aGerman
It's possible to store the output but perhaps it's not necessary.
Try
Code: Select all
set "num=5555"
for /d %%i in (%num%*) do move "%num%*.*" "%%i\"
Regards
aGerman
Re: find complete folder name based on first 4 characters?
Posted: 21 May 2012 11:50
by bridfi
wow.. thanks. it works perfectly.
now im just trying to figure out how to cycle through all the job numbers....
i was thinking of a for loop? can a for loop be within another loop?
for example, how to cycle through 6000-7000... right now it only does 6780.
Code: Select all
set "num=6780"
for /d %%i in ("P:\CURRENT JOBS\%num%*") do move "%num%*.*" "%%i\Production Documents\Scanned Documents\Plate Nestings\" > log.txt
aGerman - Thank you for your help! It is greatly appreciated!
Re: find complete folder name based on first 4 characters?
Posted: 21 May 2012 12:07
by aGerman
Untested written into the browser window:
Code: Select all
for /l %%i in (6000 1 7000) do (
for /d %%j in (%%i*) do move "%%i*.*" "%%j\"
)
Adapt it with your pathes.
FOR help message:
http://www.dostips.com/DosCommandIndex.php#FORRegards
aGerman
Re: find complete folder name based on first 4 characters?
Posted: 21 May 2012 12:38
by bridfi
Thank you!
This was a little too complex for me, its funny that it only took 2-3 lines of code..
Thanks again!
Re: find complete folder name based on first 4 characters?
Posted: 21 May 2012 13:16
by aGerman
bridfi wrote:This was a little too complex for me
For that reason I gave you the link to have a look how FOR /L works.
Code: Select all
FOR /L %variable IN (start,step,end) DO command [command-parameters]
The set is a sequence of numbers from start to end, by step amount.
So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
generate the sequence (5 4 3 2 1)
Regards
aGerman
Re: find complete folder name based on first 4 characters?
Posted: 21 May 2012 17:37
by foxidrive
'Move' might barf too unless the folder exists.
See how this goes (untested) but test it on some sample files first. Perhaps change the range to 6780,1,6780 to process only one folder.
Code: Select all
@echo off
for /L %%a in (6000,1,7000) do (
for /d %%i in ("P:\CURRENT JOBS\%%a*") do (
md "%%i\Production Documents\Scanned Documents\Plate Nestings\" 2>nul
move "%%i*.*" "%%i\Production Documents\Scanned Documents\Plate Nestings\" > log.txt
)
)