For W2k+
remove 'echo' ater checking it works as you expect it to.
@echo off
setlocal
for /f "delims=" %%a in ('dir /a:-d /b') do call :stuff "%%a"
goto :EOF
:stuff
set file=%~1
set file=%file:(=%
set file=%file:)=%
echo ren %1 "%file%"
)
Assuming by parenthesis you mean the characters ( and ), then try
the following syntax (replace C:\Myfolder\*.* with whatever folder
the files are in:
Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
FOR %%F IN (C:\MyFolder\*.*) DO CALL :FSCAN "%%F"
GOTO :EOF
:FSCAN
SET FN=%~nx1
SET FN=%FN:(=%
SET FN=%FN:)=%
:: To execute (instead of view) command, remove ECHO/{demo} below
ECHO/{demo}REN %1 "%FN%"
====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects
Note: In the Batch file shown, some commands generated are merely
ECHOed, not executed. This is so that you can see them, and judge
whether or not commands you see are indeed doing exactly what you
want. When you are satisfied with the inactive Batch commands you
see ECHOed with a "{demo}" prefix (to make it clear that they are
NOT being executed), remove the ECHO/{demo} to activate commands.
These commands will do nothing until this ECHO/{demo} is removed.
If by parenthesis you mean the characters [ and ], then replace
the ( and ) in commands:
SET FN=%FN:(=%
SET FN=%FN:)=%
with [ and ] as follows:
SET FN=%FN:[=%
SET FN=%FN:]=%
--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
Header email is rarely checked. Contact us at http://www.allenware.com/
Using both William's and foxi's ideas -
[01]@echo off
[02]for /f "delims=" %%i in ('dir /a:-d /b C:\path\*') do call :process
"%%i"
[03]for %%i in (yon ynn) do set %%i=
[04]goto :eof
[05]
[06]:process
[07]set yon=%~nx1
[08]set ynn=%yon:(=%
[09]set ynn=%ynn:)=%
[10]if "%ynn%"=="%yon%" goto :eof
[11]ren "%~dp1%yon%" "%ynn%"
[12]goto :eof
Each line begins [number]. Lines will be wrapped in transmission and need to
be rejoined. The [number] at the beginning of each line needs to be removed.
This gets over the "only works in current directory" and "attempt to rename
a file to itself" problems.
HTH
...Bill
>====Begin cut-and-paste (omit this line)
> @ECHO OFF
> FOR %%F IN (C:\MyFolder\*.*) DO CALL :FSCAN "%%F"
> GOTO :EOF
>
> :FSCAN
> SET FN=%~nx1
> SET FN=%FN:(=%
> SET FN=%FN:)=%
> :: To execute (instead of view) command, remove ECHO/{demo} below
> ECHO/{demo}REN %1 "%FN%"
>
>====End cut-and-paste (omit this line)
Exist a solution for w98?
Togli un despammed per rispondere
--
,,, e dopo che ci avranno trasformato in vegetariani, a causa del vino al
metanolo, del pesce al mercurio, dei polli alla diossina, dei maiali agli
ormoni, delle mucche, pecore e capre pazze, ci daranno da mangiare la
frutta al benzene e la verdura radioattiva.
La nostra unica salvezza sara' nel Soylent Green!
Yes. The following demo Batch file uses no third-party utilties. It
removes ( and ) characters from filenames in the current folder. Note
that this may cause some files to have the same name as others, for
example:
File(name.tmp
F)ilename).tmp
In this case, the Batch file warns that it can't rename a conflicting
file, and leaves it to you what to do.
Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (GOTO:)==(%1) %1%2 {Subroutine-Handler}
LFNFOR ON
FOR %%F IN ("*)*") DO CALL %0 GOTO: _FSCAN "%%F"
FOR %%F IN ("*(*") DO CALL %0 GOTO: _FSCAN "%%F"
LFNFOR OFF
FOR %%V IN (FNsrc FNdest CH) DO SET %%V=
GOTO EOF {=Subroutine-section-below=}
:_FSCAN (Usage: CALL %0 GOTO: _FSCAN FileName.ext)
:: Here we have all files with ( or ) in their names
SET FNsrc=%3
ECHO. SET FNdest=%3>%TEMP%.\_RENTMP.BAT
:: Remove the parentheses from filename
SET CH=28
%COMSPEC%/c %0 GOTO: _ELIDE ECHO.|debug %TEMP%.\_RENTMP.BAT>NUL
SET CH=29
%COMSPEC%/c %0 GOTO: _ELIDE ECHO.|debug %TEMP%.\_RENTMP.BAT>NUL
FOR %%C IN (CALL DEL) DO %%C %TEMP%.\_RENTMP.BAT
IF EXIST %FNdest% ECHO. Can't REName %FNSrc% - %FNdest% already exists
IF EXIST %FNdest% GOTO EOF
ECHO. Renaming %FNsrc% to %FNdest%
REN %FNsrc% %FNdest%
GOTO EOF {=Subroutine-section-below=}
:_ELIDE (Usage: %COMSPEC%/c %0 GOTO: _ELIDE ECHO.)
%3 e90 be 0 1 bf 0 1 80 3c %CH% a4 75 1 4f e2 f7 89
%3 ea0 f9 81 e9 0 1 cc
%3 g=90
%3 w
%3 q
:EOF {End-of-file}
====End cut-and-paste (omit this line)
For Win95/98/ME study/demo use. Cut-and-paste as plain-text Batch file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects
The source code for the tiny assembly program built by Debug from
the packed hex code:
e90 be 0 1 bf 0 1 80 3c %CH% a4 75 1 4f e2 f7 89
ea0 f9 81 e9 0 1 cc
is equivalent to:
90 mov si,100
93 mov di,100
96 cmp byte ptr [si],%CH%
99 movsb
9a jnz 9d
9c dec di
9d loop 96
9f mov cx,di
a1 sub cx,100
a5 int 3
where %CH% is the hex value for character to be removed.
Nice. You could save 1 byte by setting DI=SI at the top, but it's a trivial
niggle to an otherwise excellent W98/Asm
solution. I imagine someone ;-) could make it into text assembler, to avoid
reliance on debug, but it would make the solution longer.
90 BE0001 MOV SI,0100
93 89F7 MOV DI,SI ;
95 803C28 CMP BYTE PTR [SI],%CH%
98 A4 MOVSB
99 7501 JNZ 009C
9B 4F DEC DI
9C E2F7 LOOP 0095
9E 89F9 MOV CX,DI
A0 81E90001 SUB CX,0100
A4 CC INT 3
>> Exist a solution for w98?
>
>Yes. The following demo Batch file uses no third-party utilties. It
>removes ( and ) characters from filenames in the current folder. Note
>that this may cause some files to have the same name as others, for
>example:
> File(name.tmp
> F)ilename).tmp
Beatiful, work!
>Nice. You could save 1 byte by setting DI=SI at the top, but it's a trivial
>niggle to an otherwise excellent W98/Asm
>solution. I imagine someone ;-) could make it into text assembler, to avoid
>reliance on debug, but it would make the solution longer.
>
>90 BE0001 MOV SI,0100
>93 89F7 MOV DI,SI ;
First, sorry for bad english!
Good! But the lenght for the assembler routine in this case not is not
important.
The first step is functionality!
Thank!