Help - Search - Members - Calendar
Full Version: Batch DIR output formatting
MSFN Forums > Coding, Scripting and Servers > Programming (C++, Delphi, VB, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
twig123
Hey all,

I'm can seem to figure out the code to do this...
I'm trying to make a batch file do a "DIR /B/ON" and list only the file names in this formatting like below into a variable

file1.exe|file2.exe|file3.exe|file4.exe (separated by a | "pipe" )

Any ideas on how to go about doing so?

thanks
Scr1ptW1zard
If you only want the files, use dir /b /on /a-d [d:\path].

Like this:

CODE
@echo off

setlocal enabledelayedexpansion
for /f "tokens=*" %%# in ('dir /b /on /a-d c:\') do set _lst_=!_lst_!%%#^^^|
echo !_lst_!
endlocal


Yzöwl
I cannot immediately see a reason to have this data as a variable therefore I'll assume you'd wish it in a file.

In the code below, change:
  • %userprofile%\desktop to reflect the directory you wish listing
  • %temp%\_$out.log to reflect your intended output file
CODE
@Echo off&Setlocal
Set "#=%userprofile%\desktop"
Set "_=%temp%\_$out.log"
Type Nul>"%_%"
For /f "delims=" %%_ In ('Dir/b/a-d "%#%"') Do Echo:|Set/p "=%%_|">>"%_%"
twig123
@Scr1ptW1zard & Yzöwl -Thanks for the responces, I will test both suggestions and see if either formatting will work for me.

QUOTE (Yzöwl @ Jun 7 2008, 08:30 AM) *
I cannot immediately see a reason to have this data as a variable therefore I'll assume you'd wish it in a file.
Well, I'm trying to automate boooggy's WMP11 slipstreamer to take any hotfixes in a certine folder and integrate them all, without having to manually enter the names of every file

so to end up something like this:
CODE
Set Path=E:\Twig06\~Source~\Addins\2008-26-05\~files~
REM -- %path% is hard coded path at the moment just for testing
Set WMP11Patches=%path%\WMP11\Patches
REM Folder to place all patches for WMP11 to be slipstreamed

WMP11Slipstreamer.exe /hotfix:"%WMP11Patches%|%OutputFromArrayToListFilesToRuN%"
...We could also use this same approach for RyanVM integrator as well as nLite and Driverpacks, however, the output would need to be in a different format for each but still the same basic format of pulling the file names and putting them into a variable. Thus making it very easy for those of us who use the same tweaks all the time, however just need updates added to a new build, resulting in a completely unattended creation of a Windows Build.... only work required is to place the updated files into specific folders.

Thanks both!
twig123
@Yzöwl -
I tested and your coding is working very well! If it is possible, the only other things are to place the output into a variable and to remove the | (pipe) after the very last file.
Ex: take the output from the above code "file1.exe|file2.exe|file3.exe|" and remove the | after file3.exe

A very greatful Twig says TYVM for taking the time to try to helpme in my quests smile.gif
Yzöwl
Well I've no idea about this tool or its commandline options etc. therefore I'll assume that your above command is correct and take a stab at this!
CODE
@Echo off&Setlocal
Set p_=E:\Twig06\~Source~\Addins\2008-26-05\~files~
Set #=%p_%\WMP11\Patches
Set "_=%temp%\_$out.log"
Type Nul>%_%
For /f "delims=" %%_ In ('Dir/b/a-d "%#%"') Do Echo:|Set/p "=%%_|">>%_%
For /f "usebackq delims=" %%_ In ("%_%") Do (Set $="%%_")
Del %_%&Set $="%$:~1,-2%"
For /f "delims=" %%_ In (%$%) Do (
Start "" /wait WMP11Slipstreamer.exe /hotfix:"%#%|%%_")
twig123
Here, this might help:


the output for the WMP11Slipstreamer.exe /hotfix: command is what we are trying to achive. The needed format is:
WMP11Slipstreamer.exe /hotfix:"FolderPathToHotfixes|hotfix1.exe|hotfix2.exe|hotfix3.exe" ...etc... so we shouldn't need to send the output through another array. so the output to that is being put into the _$out.log is exactly the info we need to throw into the after the /hotfix:" switch (minus the end | )

to look the final output like this:
Set p_=E:\Twig06\~Source~\Addins\2008-26-05\~files~
Set #=%p_%\WMP11\Patches
Set "_=%temp%\_$out.log"
WMP11Slipstreamer.exe /hotfix:"%#%|OutputFrom_$out.log(MinusTrailing|)"

another example (exact syntax as if I were manually typing this info into a command line):
CODE
WMP11Slipstreamer.exe /hotfix:"E:\Twig06\~Source~\Addins\2008-26-05\~files~\WMP11\Patches|kb928788.exe|kb929399.exe|kb929773.exe"

(forum makes it look like this is multiple lines, but it is actually all on the same line)
Yzöwl
The example I gave was intended to do just that!

Is there something I missed? did you try it as is?
twig123
Sry, i just looked at it b4...
I guess I didn't understand why it would go through a 2nd array... but you are right, it does exactly what I was wanting biggrin.gif
TYVM!

(I might have to contract your services again if I get stuck with the other 2 programs, but I will take a stab at those for now, I just couldn't figure out how to get the |'s in there, as it would keep telling me it was an invalid syntax every time I tried something.)

Thanks again!
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.