Reputation: 365
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.
Upvotes: 0
Views: 64
Reputation: 2565
- 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"
Upvotes: 0
Reputation: 56180
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: = !
)
Upvotes: 1
Reputation: 41
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
Upvotes: 0