China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-09 05:54
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How do I add an extension to files that don't have one? View 2,032 Replies 15
Original Poster Posted 2008-07-12 13:21 ·  中国 广东 深圳 宝安区 电信
中级用户
★★
Credits 358
Posts 130
Joined 2005-11-12 16:29
20-year member
UID 45117
Status Offline
Floor 2 Posted 2008-07-12 13:24 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline

@echo off
for /f "delmis=" %%i in ('dir /s /a-d /b 盘符:\s.h.e*') do if "%%~xi" neq ".wma" ren "%%i" %%~ni.wma


[ Last edited by zw19750516 on 2008-7-12 at 01:45 PM ]
批处理之家新域名:www.bathome.net
Floor 3 Posted 2008-07-12 13:40 ·  中国 广东 深圳 宝安区 电信
中级用户
★★
Credits 358
Posts 130
Joined 2005-11-12 16:29
20-year member
UID 45117
Status Offline
Originally posted by zw19750516 at 2008-7-12 13:24:

@echo off
for /f "delmis=" %%i in ('dir /s /a-d /b s.h.e*') do if "%%~xi" neq ".wma" ren "%%i" %%~ni.wma


Thanks for your reply, but it doesn't seem to work
Floor 4 Posted 2008-07-12 13:42 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by yywd at 2008-7-12 13:40:


Thanks for your reply, but it doesn't seem to work

Where are you running it from?
Try this:

@echo off
for /r %%i in (*s.h.e*) do if "%%~xi" neq ".wma" ren "%%i" %%~ni.wma

ps: the beginning of post #2 was written wrong, I've corrected it. OP, please change 盘符: to the actual drive letter.

[ Last edited by zw19750516 on 2008-7-12 at 01:47 PM ]
批处理之家新域名:www.bathome.net
Floor 5 Posted 2008-07-12 13:46 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Q: Why doesn't it work?
A: Go find the phone number of some old army doctor on a utility pole; he specializes in treating that and guarantees a cure. If the treatment cycle is a bit long, I suggest listing your test environment, test cases, and error messages so everyone can help you solve the problem.
Floor 6 Posted 2008-07-12 14:10 ·  中国 广东 深圳 宝安区 电信
中级用户
★★
Credits 358
Posts 130
Joined 2005-11-12 16:29
20-year member
UID 45117
Status Offline
Originally posted by zw19750516 at 2008-7-12 13:42:

Where did you put it to run?
Try this:

@echo off
for /r %%i in (*s.h.e*) do if "%%~xi" neq ".wma" ren "%%i" %%~ni.wma

ps: the one in post #2 ...


s.h.e-talking vi got changed to s.h.wma
Jiangnan Sentiment s.h.e Ⅱ got changed to Jiangnan Sentiment s.h.wma
s.h.e-Jiangnan Sentiment intro did not change
Floor 7 Posted 2008-07-12 14:18 ·  中国 山东 聊城 联通
初级用户
★★
Credits 73
Posts 51
Joined 2007-08-31 10:04
18-year member
UID 96241
Gender Male
Status Offline
In folder properties, turn off the option to hide extensions, then refresh and see whether they have extensions. The way it is for you, with some music files seeming to have extensions and some not, I guess it's probably caused by hidden extensions...
Floor 8 Posted 2008-07-12 14:20 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
I understand now, the problem is with the . in s.h.e. This should work now, right:

@echo off&setlocal enabledelayedexpansion
for /r %%i in (*s.h.e*) do (
set str=%%~nxi&set str=!str:s.h.e=she!
ren "%%i" !str!
)
for /r %%i in (*she*) do if "%%~xi" neq ".wma" ren "%%i" "%%~ni.wma"


[ Last edited by zw19750516 on 2008-7-12 at 02:25 PM ]
批处理之家新域名:www.bathome.net
Floor 9 Posted 2008-07-12 14:32 ·  中国 广东 深圳 宝安区 电信
中级用户
★★
Credits 358
Posts 130
Joined 2005-11-12 16:29
20-year member
UID 45117
Status Offline
Originally posted by zw19750516 at 2008-7-12 14:20:
I understand now, the problem is with the . in s.h.e. This should work now, right:

@echo off&setlocal enabledelayedexpansion
for /r %%i in (*s.h.e*) do (
set str=%%~nxi&set str=!str:s.h. ...


Don't change s.h.e to she, or the lyrics can't be associated

江南情怀s.h.e Ⅱ
s.h.e-talking vi
did not change
Floor 10 Posted 2008-07-12 14:35 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Are there files other than wma? If not, then just do a plain dir and change the ones without extensions, don't worry about SHE
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 11 Posted 2008-07-12 14:59 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
致精致简!
Floor 12 Posted 2008-07-12 15:03 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
第一高手 第二高手

Floor 13 Posted 2008-07-12 15:08 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
26933062 and I replied almost at the same time, so I deleted my own post. But after brother 26933062 corrects it, it should be changing if /i not ren to move /y
@echo off&setlocal enabledelayedexpansion
for /r %%i in (*s.h.e*) do (
set "str=%%~i"
if /i not "!str:~-4!"==".wma" move /y "%%i" "%%i.wma"
)
pause


[ Last edited by fastslz on 2008-7-12 at 03:13 PM ]
第一高手 第二高手

Floor 14 Posted 2008-07-12 15:10 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Thanks for the reminder, corrected
To be this careless is really unforgivable!...
致精致简!
Floor 15 Posted 2008-07-12 15:24 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Another method
@echo off
for /f "delims=*" %%i in ('dir /s /a-d /b *s.h.e*^|findstr /i /e /v ".wma"') do move /y "%%i" "%%i.wma"
pause
第一高手 第二高手

Forum Jump: