find complete folder name based on first 4 characters?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bridfi
Posts: 4
Joined: 18 May 2012 12:39

find complete folder name based on first 4 characters?

#1 Post by bridfi » 18 May 2012 12:47

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

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

Re: find complete folder name based on first 4 characters?

#2 Post by aGerman » 18 May 2012 13:57

Code: Select all

for /d %%i in (4224*) do echo %%i

Not quite sure what exactly you're looking for.

Regards
aGerman

bridfi
Posts: 4
Joined: 18 May 2012 12:39

Re: find complete folder name based on first 4 characters?

#3 Post by bridfi » 18 May 2012 15:14

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!

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

Re: find complete folder name based on first 4 characters?

#4 Post by aGerman » 18 May 2012 16:56

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

bridfi
Posts: 4
Joined: 18 May 2012 12:39

Re: find complete folder name based on first 4 characters?

#5 Post by bridfi » 21 May 2012 11:50

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!

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

Re: find complete folder name based on first 4 characters?

#6 Post by aGerman » 21 May 2012 12:07

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#FOR

Regards
aGerman

bridfi
Posts: 4
Joined: 18 May 2012 12:39

Re: find complete folder name based on first 4 characters?

#7 Post by bridfi » 21 May 2012 12:38

Thank you!

This was a little too complex for me, its funny that it only took 2-3 lines of code..

Thanks again!

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

Re: find complete folder name based on first 4 characters?

#8 Post by aGerman » 21 May 2012 13:16

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: find complete folder name based on first 4 characters?

#9 Post by foxidrive » 21 May 2012 17:37

'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
)
)

Post Reply