Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

Listing a files/Directories , but i would want in one row

I'm trying listing a directory, but i would want output in one row. could any give me a hand?.

Actually:
dir c:\ /ad /b /-p /o:gen
file1
file2
file2
.
but i want this output: file1 file2 file3....

Thanks in advance
0
jpvhack
Asked:
jpvhack
1 Solution
 
BrainartsCommented:
The only way i see to make it is to Output the listing to a file

dir c:\ /ad /b /-p /o:gen > listing.txt

Then Reprocess the file with vba script or any other script to replace the  CRLF line terminator with the file separator you need for example :" ,"

This can be automated very easyly
0
 
SalmanZGCommented:
If you need to do this for once, do this:

1. dump the out to a text file by appending  "> output.txt" to you dir command.
e.g. dir /b > output.txt

2. Open the file in MS word. Goto find and replace. Replace ^p with a blank/space.

If you need to do it repeatedly - thats another story.

0
 
jpvhackAuthor Commented:
It should carry out in a file, in only batch file, or vb script file.

Thanks
0
 
oBdACommented:
Save this as LineDir.cmd or Whatever.cmd, and simply pass it the folder to list as first argument:
linedir C:\
@echo off
setlocal enabledelayedexpansion
set Options=/ad /b /-p /o:gen
if "%~1"=="" (echo Syntax: %~nx0 ^<Folder^>&goto :eof)
for /f "delims=" %%a in ('dir %Options% "%~1"') do set Line=!Line! %%a
set Line=%Line:~1%
echo.%Line%

Open in new window

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now