0

Hi I would like to know if it is possible to get a listing of files and folders without the part between parenthensis by using the command prompt or a batch file.

When I use dir /b i get:

Lenovo 48394 Dual (48437873) Red
Lenoxx smoth 3030 (1545308)
Logitech razer 220 (04948393)
Microsoft V-3000x (4837483449) Black

But what I need is:

Lenovo 48394 Dual Red
Lenoxx smoth 3030
Logitech razer 220
Microsoft V-3000x Black

Thanks in advance.

Ricardo Bohner
  • 301
  • 2
  • 10

3 Answers3

1

To simply remove the (.....) part:

@echo off
for /f "tokens=1,3 delims=()" %%a in ('dir /b') do echo %%a%%b

If the two spaces disturb you:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,3 delims=()" %%a in ('dir /b') do (
  set "line=%%a%%b"
  echo !line:  = !
)
Stephan
  • 53,940
  • 10
  • 58
  • 91
0

It's not really Win CMD solution, but if you could use the Windows Subsystem for Linux, the sed utility with regular expression replace will work.

sed -e 's/(.*)//g' input_file

this command reads input data from input_file and prints the result to the stdout. The (.*) regex matches any text between parenthesis and the parenthesis itself

UPD: It looks like you can use Windows Powershell. Refer this answer

Bragnikita
  • 41
  • 1
  • 4
  • Thanks but I need a Windows solution. About that powershell part I'm not sure how to use it for my needs I tried: get-content somefile.txt | %{$_ -replace "(*)",""} with no success. – Ricardo Bohner Oct 27 '19 at 15:53
0

  • When it is necessary to get parenthetical content (??) by removing only the parentheses:
@echo off & setlocal enabledelayedexpansion & title %~n0

for /f ^tokens^=* %%i in ('dir /b "*.*" ^|find /v ".cmd"')do call :^[ "%%~i" && echo=!_str!
exit /b 

:^[
set _str=%~1
for /f ^tokens^=* %%S in ('cmd /c set /p "=%_str:)=%"^<nul')do call set _str=%%S
for /f ^tokens^=* %%S in ('cmd /c set /p "=%_str:(=%"^<nul')do call set _str=%%S
exit /b 

I can suggest you to know unxutils, these are some linux executables already ported to Windows platform, including sed, less, cat, atil, etc..

Unxutils is available on this site: http://unxutils.sourceforge.net

So, try the @Bragnikita answer (tested) in for loop!

for /f ^tokens^=* %i in ('dir /b "*.*" ^|find /v ".cmd"')do @echo/%i | sed -e "s/(.*)//g"

Io-oI
  • 2,514
  • 3
  • 22
  • 29