0

I felt it was better to ask this separately rather than expect an answer from my comment on my previous post.

I already have variables set for the directory number %jobn% which is unique is there a way I can search for the unknown element to add to another variable, I know via the command line I can run Dir D09854* and I will get a single report with the full name, can this be collected somehow and add to a named variable?

S:\SWDA\HBOS>dir d09854*
 Volume in drive S is Images
 Volume Serial Number is FE8F-38FE

 Directory of S:\SWDA\HBOS

18/02/2013  10:29    <DIR>          D09854_Parent Test

I want to add the elements after "_" to a variable %DirDesc% so I can create the full path by combining %jobn%%DirDesc% to get "D09854_Parent Test"

timrau
  • 22,578
  • 4
  • 51
  • 64
CAD-wiz
  • 39
  • 1
  • 7
  • question is not clear to me - to confirm - under HBOS directory there are bunch of sub directories - you want to list those sub directories and then add extract text to each directory ? – Baljeetsingh Sucharia Feb 18 '13 at 15:12
  • Under HBOS there will be multiple dirs all set out in the format above. I need to add another driectory template to one of those folders, my routine already gets the user to add the numbered (structured) element but I need a user friendly way of getter the descriptive element added to the path without the user typing it in, so my thoughts were to grab it somehow by way of a listing and adding it to another definition, hope this helps. – CAD-wiz Feb 18 '13 at 15:22
  • FOR /F %%I IN ('DIR /b %src%D0%Pjob1%%Pjob2%%Pjob3%%Pjob4%_*') DO SET V=%%I A lot more searching has given me the above code which almost gives me what I need, except it does not pick up the whole trailing description but stops at the first space so instead of: > D09854_Parent Test I get: > D09854_Parent Some descriptions may have a number of spaces so I need to capture the whole thing. Hopefully someone can get me the missing step :) – CAD-wiz Feb 18 '13 at 17:08
  • 1
    Possible duplicate of [Batch file - Write list of files to variable](https://stackoverflow.com/questions/3238433/batch-file-write-list-of-files-to-variable) – Dave Jarvis Nov 28 '17 at 01:19

1 Answers1

0

dir d09854* /b will recover the full folder name in one line, without the extra cruft, if that's any use? What are you writing this widget in? Does it have to be Good Old Fashioned DOS, or can the newer Command extensions be used?

With limited old DOS, I can't think of a way to get that into a SET Variable without piping it to a temporary batch file, having first ECHO'd a set variable= into it, and using >> in the pipe to append to it... and then CALL the temporary batch file to execute the command!

AjV Jsy
  • 5,799
  • 4
  • 34
  • 30
  • I'm working with Windows 7 command line. `dir d09854* /b` is what I'm after but I need to retrieve it and add it to my xcopy path. – CAD-wiz Feb 18 '13 at 16:01
  • I don;t know why I can't comment on the original question section, so I hope you find this. There's a `For /d` option for directories - if I try this in the root folder I get `Documents and Settings` in a variable : `for /d %p in (do*) do set myvar=%p` – AjV Jsy Feb 18 '13 at 20:56
  • Great, thanks Fuzzy, this appears to work. I was almost there but only getting the first part of the description to the first space. A little more testing and my routine will be completed cheers. – CAD-wiz Feb 19 '13 at 09:30