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-09-24 03:16
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask for a batch script to delete files View 3,123 Replies 27
Floor 16 Posted 2006-11-07 03:36 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
20-year member
UID 63324
Gender Male
Status Offline
The effect of the delay variable you want:

The second method:


@echo %dbg% off
setlocal enabledelayedexpansion

set b=0
for /l %%i in (0,1,4) do (
echo !b!
call set /a b+=1
)


The output is as follows:

C:\TEMP\k>b.bat
0
1
2
3
4
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 17 Posted 2006-11-07 03:44 ·  中国 内蒙古 呼和浩特 电信
初级用户
Credits 50
Posts 23
Joined 2006-11-03 23:05
19-year member
UID 69459
Gender Male
Status Offline
Brother upstairs, you are completely taking a shortcut.

In this way, I require:

@echo %dbg% off

for /L %%i in (0,1,4) do (
echo %%i
)
echo %%i cannot be displayed using %%i. Another variable needs to be used for display, and there should be no relation at all between this variable and %%i
Floor 18 Posted 2006-11-07 03:47 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
20-year member
UID 63324
Gender Male
Status Offline
Brother onlykier, I have read your code example on floor 8 and have run and debugged it many times...

However, the problem you were trying to address above didn't follow your line of thinking :)

You thought about how to solve a problem, but almost all the places where errors occurred were affected by some basic knowledge points :)
And Brother onlykier is learning very fast, but in the end, he still has to return to those basic variable assignments, SET, delay variables, For structures, operation and escape of special symbols...

So, it is suggested that onlykier retype all the knowledge points mentioned in the following link line by line from start to finish ~:)
Then come back and look again, I believe Brother onlykier will surpass the present...
And this whole process may only take a few days or even one or two days.
But doing this whole thing from start to finish in these one or two days, I believe onlykier will never have problems again,
but will start to enter the state of knowing how to handle some unknown problems and can find solutions very quickly :)


About SET variables, delay variables, usage of various symbols...
http://www.cn-dos.net/forum/viewthread.php?tid=24549&fpage=1

[ Last edited by redtek on 2006-11-7 at 03:57 AM ]
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 19 Posted 2006-11-07 04:02 ·  中国 内蒙古 呼和浩特 电信
初级用户
Credits 50
Posts 23
Joined 2006-11-03 23:05
19-year member
UID 69459
Gender Male
Status Offline
Brother upstairs, just kill me
I'll give another example
I just want to display the first line, but the following code displays all, why?
@echo off
dir d: /b>>d:\1.txt
set c=0
echo 1,%c%
for /f %%i in (d:\1.txt) do (
if %c% equ 0 (set c=1
echo 2,%c%
echo %%i)
)

[ Last edited by onlykier on 2006-11-6 at 03:12 PM ]
Floor 20 Posted 2006-11-07 04:10 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
20-year member
UID 63324
Gender Male
Status Offline
Brother upstairs, I won't kill you, or you let me commit suicide~:)

In your for %%i in (d:\1.txt) do (without adding the /f parameter here, can you read the file content?)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 21 Posted 2006-11-07 04:12 ·  中国 内蒙古 呼和浩特 电信
初级用户
Credits 50
Posts 23
Joined 2006-11-03 23:05
19-year member
UID 69459
Gender Male
Status Offline
I have made modifications. Brother upstairs, what's your QQ number? I'm so anxious waiting for the answer.
Floor 22 Posted 2006-11-07 04:14 ·  中国 内蒙古 呼和浩特 电信
初级用户
Credits 50
Posts 23
Joined 2006-11-03 23:05
19-year member
UID 69459
Gender Male
Status Offline
set c=1
echo 2,%c%
Why is the output %c% still 0?
Floor 23 Posted 2006-11-07 04:28 ·  中国 内蒙古 呼和浩特 电信
初级用户
Credits 50
Posts 23
Joined 2006-11-03 23:05
19-year member
UID 69459
Gender Male
Status Offline
Forum pagination, didn't see redtek's second method ^^!
set b=0
for /l %%i in (0,1,4) do (
echo !b!
call set /a b+=1
And then ask, why is there a call here?
Floor 24 Posted 2006-11-07 04:30 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
20-year member
UID 63324
Gender Male
Status Offline

@echo %dbg% off
:: Delay variable
setlocal enabledelayedexpansion

dir d: /b>>d:\1.txt
set c=0
echo 1,%c%

:: /f parameter
:: "delims=" can read strings with spaces...
for /f "delims=" %%i in (d:\1.txt) do (

if !c! equ 0 (
set c=1
echo 2,!c!
echo %%i
)
)

It is suggested to write code with indentation like this:)



[ Last edited by redtek on 2006-11-7 at 04:36 AM ]
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 25 Posted 2006-11-07 04:30 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
```
@echo off
dir c:\ /b>>c:\1.txt
set /p s=<c:\1.txt
echo %s%
pause
```
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +2 2006-11-07 04:33
Floor 26 Posted 2006-11-07 04:31 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
20-year member
UID 63324
Gender Male
Status Offline
Originally posted by onlykier at 2006-11-7 04:28:
Forum page turning, didn't see redtek's second method ^^!
set b=0
for /l %%i in (0,1,4) do (
echo !b!
call set /a b+=1
Please ask again, why is there a call here?


That call should be deleted, that was left over from another experiment when copying and forgetting to delete it~ : )
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 27 Posted 2006-11-07 04:32 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
20-year member
UID 63324
Gender Male
Status Offline
Brother lxmxn's code is very concise, appreciate it~:)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 28 Posted 2006-11-07 04:48 ·  中国 内蒙古 呼和浩特 电信
初级用户
Credits 50
Posts 23
Joined 2006-11-03 23:05
19-year member
UID 69459
Gender Male
Status Offline
@echo off
dir c:\ /b>>c:\1.txt
set /p s=<c:\1.txt
echo %s%
pause
Why does this code only display the first line? I thought it should display many lines because the content of c:\1.txt is assigned to s.
Forum Jump: