2

Many thanks for the help but...

Using Windows 7 x64 running command from a batch file in a particular folder

I use many paq8/paq9 command line compressors to back up my files. Of these, many can't read directory structures, so individual file names need to be put into a particular single-line syntax. I can get a list of files from a text file from a specific directory, but they are naturally in singles. I need to create a text file that will give the contents, but all in 1 line separated by a space. My batch is here:

dir /a /b /-p /o:gen >%USERPROFILE%\Desktop\file_list_full.txt

I want to be able to pop this line into a batch file in ANY folder and just run it to create a text list of folder contents

As an example, this will give:

Hello.exe

Help.txt

Big.png

sound.ogg

I need it to be:

Hello.exe Help.txt Big.png sound.ogg

Example of paq compression structure and to why this needs to be done especially when you may have a couple hundred files in a folder!!

paq9a a Archive.paq9a -8 -c feasting.exe License.txt INFO.txt data.win D3DX9_43.dll data.big dbr.ut

How can I do this?

If I leave the text file to create as is. Is there a way then of replacing "new Line" with a "space" to get the required result?

3 Answers3

2

I think you may want wide-format output, Try /w

This option is incompatible with /B so use findstr to filter out headings and summaries.

 C:> dir /a-d /w | findstr /B [a-zA-Z0-9]
 Big.png     Hello.exe   Help.txt    sound.ogg

Caveat: above tested on Win7. You appear to have a different O/S.


If you have lots of finicky requirements you may need to bring out the big hammer. I like Perl but your mileage may vary.

C:> perl -e "print join ' ', glob('*')"
Big.png Hello.exe Help.txt sound.ogg
0

dir /a /b /-p /o:gen >%USERPROFILE%\Desktop\file_list_full.txt /w

for "wide"

If you're hardcore about the space, meaning a true ANSI/Ascii value, I'd pipe the command through GSAR with a find/replace.

Reset the default cmd window parameter to an ungodly value such as "9999" for your entire system or the particular instruction and you'll get the long line return without wrapping.

You should respond if the space is absolutely necessary and with the character code value, it's a nitty detail and you can share more details of where you plan to reuse the output since it might give us the necessary info.

0

An alternative to 'pure' cmd line (which you may find useful if you need 'ad hoc' lists):
Win explorer allows to drop multiple selections onto an app - in particular, batch file.

Simple example - create batch file with following content:

@echo off
echo %*
pause

then open explorer window so you have it visible and drop multiple selected files onto it. It will simply list them (and pause so you could read), but add redirection and you have your list saved to file, or replace echo with your compressor command and it will run on a list.

update: to get filenames only

@echo off
setlocal

:loop
  if [%1]==[] goto end
  set arg=%arg% "%~nx1"
  shift
  goto loop

:end
echo %arg%
pause

Still limited by max cmd length (8192) as I outlined in my linked answer

wmz
  • 7,358