简体   繁体   中英

BAT FILE: Rename wav files in directory with the exception of a single file name?

I'm trying to write a bat file that does this:

  1. Deletes two files: Temp.Wav Temp.lip
  2. Renames any wav file in the directory to temp.wav

I'm stumped unfortunately, been at it for hours.

@echo off
setlocal enableDelayedExpansion
for %%F in (*.wav) do (
  set "name=%%F"
  ren "!name!" "!name:Temp.wav!"
)

This task is very easy to solve with a small batch file. The directory path on second line must be adapted.

@echo off
set "WorkingDirectory=C:\Temp\WavFiles"

if exist "%WorkingDirectory%\Temp.wav" del "%WorkingDirectory%\Temp.wav"
if exist "%WorkingDirectory%\Temp.lip" del "%WorkingDirectory%\Temp.lip"

rem The loop below renames just first found *.wav file in the directory.
for %%F in ("%WorkingDirectory%\*.wav") do (
   ren "%%F" Temp.wav
   goto :EndBatch
)
:EndBatch
set WorkingDirectory=

This is a minimalist way of doing it - remove the cd command to make it operate in the current folder.

@echo off
cd /d "c:\folder"
del Temp.wav 2>nul
del Temp.lip 2>nul
ren *.wav Temp.wav 2>nul

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM