Problema col ciclo FOR

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
betto
Posts: 3
Joined: 06 Feb 2015 03:09

Problema col ciclo FOR

#1 Post by betto » 06 Feb 2015 03:34

Ciao a Tutti,

ho il seguente file.bat

@echo off

setlocal enabledelayedexpansion
set filecontent=
set separator=/

C:
cd C:\inetpub\wwwroot\aesi_quality\fpdb
echo ^$ > prova.txt
dir 20*.bat / B >> prova.txt


for /f %%a in (prova.txt) do (
set currentline=%%a
set filecontent=!filecontent!%separator%!currentline!
)


if "%filecontent:~3,2%" == "20" (
echo "%filecontent%"
for %%f in (20*.bat) do (
%%f >> C:\inetpub\wwwroot\aesi_quality\fpdb\ries_log.txt
del %%f )
)


if not "%filecontent:~3,2%" == "20" ( echo %DATE% %TIME:~0,5% Nessun file trovato >> C:\inetpub\wwwroot\aesi_quality\fpdb\ries_log.txt )


del prova.txt
echo "ciao"
Pause


Questo programma funziona solo che ha un problema dopo il ciclo for.
Infatti dopo l' esecuzione corretta di esso non viene eseguito tutto cio' che sta al di fuori dell' if:
quindi non mi esegue il del prova.txt e nemmeno echo "ciao"

Se commento il ciclo for, allora tutto e' a posto...
Pero' ho bisogno che il file venga cancellato ... come risolvere il problema ??

Come mai succede cio' ?? Grazie mille in anticipo

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Problema col ciclo FOR

#2 Post by foxidrive » 06 Feb 2015 04:01

Can you repost in English?

betto
Posts: 3
Joined: 06 Feb 2015 03:09

Re: Problema col ciclo FOR

#3 Post by betto » 06 Feb 2015 04:09

Sorry,

I' ve a problem with this file BAT

@echo off

setlocal enabledelayedexpansion
set filecontent=
set separator=/

C:
cd C:\inetpub\wwwroot\aesi_quality\fpdb
echo ^$ > prova.txt
dir 20*.bat / B >> prova.txt


for /f %%a in (prova.txt) do (
set currentline=%%a
set filecontent=!filecontent!%separator%!currentline!
)


if "%filecontent:~3,2%" == "20" (
echo "%filecontent%"
for %%f in (20*.bat) do (
%%f >> C:\inetpub\wwwroot\aesi_quality\fpdb\ries_log.txt
del %%f )
)



if not "%filecontent:~3,2%" == "20" ( echo %DATE% %TIME:~0,5% Nessun file trovato >> C:\inetpub\wwwroot\aesi_quality\fpdb\ries_log.txt )

del prova.txt
echo "ciao"
Pause

we can not understand why all the codes after the cicle for (in red) are not executed. In particular del prova.txt and echo "ciao"

Why ??

Thanks a lot in advance !!!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Problema col ciclo FOR

#4 Post by Squashman » 06 Feb 2015 09:17

Change this line.

Code: Select all

%%f >> C:\inetpub\wwwroot\aesi_quality\fpdb\ries_log.txt 

to

Code: Select all

CALL %%f >> C:\inetpub\wwwroot\aesi_quality\fpdb\ries_log.txt 

betto
Posts: 3
Joined: 06 Feb 2015 03:09

Re: Problema col ciclo FOR

#5 Post by betto » 10 Feb 2015 09:06

Thanks a lot !!!!

Post Reply