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-12 18:35
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Problem changing extensions with FOR View 737 Replies 2
Original Poster Posted 2010-04-08 22:47 ·  中国 浙江 温州 电信
新手上路
Credits 8
Posts 6
Joined 2008-04-17 13:14
18-year member
UID 116144
Gender Male
Status Offline
I first used FOR to rename .EXE to .EXE.BAK
@echo off
set pth=%cd%
for /r "%pth%" %%a in (*.EXE) do move /y "%%a" "%%a.BAK"

Later I wanted to try changing them back, but I don't know what's wrong with the statement below. I kept looking it over again and again, but it's still not right.
@echo off
set pth=%cd%
for /r "%pth%" %%a in (*.BAK) do (
set file=%%a
move /y "%%a" "%file:~0,-4%"
)
Could some expert give me some pointers?
Floor 2 Posted 2010-04-08 23:07 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
@echo off
setlocal enabledelayedexpansion
set pth=%cd%
for /r "%pth%" %%a in (*.BAK) do (
set file=%%a
move /y "%%a" "!file:~0,-4!"
)

You didn't use delayed variable expansion.
Floor 3 Posted 2010-04-08 23:10 ·  中国 浙江 温州 电信
新手上路
Credits 8
Posts 6
Joined 2008-04-17 13:14
18-year member
UID 116144
Gender Male
Status Offline
Oh, thanks.
Forum Jump: