Jump to content

Batch DIR output formatting


Recommended Posts

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

Link to comment
Share on other sites


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

@Echo off&Setlocal
Set "#=%userprofile%\desktop"
Set "_=%temp%\_$out.log"
Type Nul>"%_%"
For /f "delims=" %%_ In ('Dir/b/a-d "%#%"') Do Echo:|Set/p "=%%_|">>"%_%"

Link to comment
Share on other sites

@Scr1ptW1zard & Yzöwl -Thanks for the responces, I will test both suggestions and see if either formatting will work for me.

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:

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!

Edited by twig123
Link to comment
Share on other sites

@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 :)

Link to comment
Share on other sites

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!

@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:"%#%|%%_")

Link to comment
Share on other sites

Here, this might help:

wmp11tv8.th.jpg

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

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)

Edited by twig123
Link to comment
Share on other sites

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 :D

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!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...