file getting bigger (over 7 Go) and can't stop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
leama
Posts: 2
Joined: 03 Feb 2015 05:10

file getting bigger (over 7 Go) and can't stop

#1 Post by leama » 03 Feb 2015 05:35

Hello,

I'm having a serious problem with a batch file that does simple things like moving files to another folder, copying several files into a single file, and then moving these files to different folders.

Then, I have a planified task (Windows server 2008) that executes this batch file every 10 minutes.

Normally, it takes just 1 minute to do all its job. And the output file (cli.txt) size is about 60 Ko. But sometimes, not always, just occasionally, I can't stop it. The output file is always occupied by "System" process and it gets bigger and bigger without stopping at all. I dare not kill the "System" process. Eventually I have to shut down the server.

Here is my batch file without a word changed:

x:
cd "\interface\Exp Clients"
move "*.txt" "x:\interface\Exp Clients\TEMP\"
cd TEMP
if exist *.txt (type *.txt >> cli.txt)
set dateheure=%date:~0,2%-%date:~3,2%-%date:~6,4%_%time:~0,2%h%time:~3,2%min%time:~6,2%s
set dateheure=%dateheure: =%
copy "cli.txt" "x:\interface\Exp Clients\HISTO\cli_%dateheure%.txt"
move "cli.txt" "x:\interface\Exp Clients\"
move "*.txt" "x:\interface\Exp Clients\HISTO\"

Any idea why this happens? Thanks!

Lea

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

Re: file getting bigger (over 7 Go) and can't stop

#2 Post by foxidrive » 03 Feb 2015 06:15

Change this line:

Code: Select all

if exist *.txt (type *.txt >> cli.txt)

To this:

Code: Select all

if exist *.txt (type *.txt >> cli.tmp & move cli.tmp cli.txt)


because the first one is also typing the file that is being created.

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

Re: file getting bigger (over 7 Go) and can't stop

#3 Post by Squashman » 03 Feb 2015 07:13

You basically created a cyclical process.

leama
Posts: 2
Joined: 03 Feb 2015 05:10

Re: file getting bigger (over 7 Go) and can't stop

#4 Post by leama » 03 Feb 2015 07:32

OK. I think I understand. cli.txt meets the condition *.txt, right?

I will test foxidrive's suggestion.

Thanks a lot, both of you!

Lea

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: file getting bigger (over 7 Go) and can't stop

#5 Post by Compo » 03 Feb 2015 10:24

There also seems to be possible problems using multiple calls to %TIME% and no need for the TEMP directory, (little point in moving all of your text files twice)!

Code: Select all

@Echo Off
SetLocal
(Set BD=X:\Interface\Exp Clients)
If Not Exist "%BD%\*.txt" Exit/B
If /I "%CD%" NEq "%BD%" PushD %BD%
(Set D=%DATE%)
(Set H=%TIME%)
(Set DH=%D:~,2%%D:~3,2%-%D:~6,4%_%H:~,2%h%H:~3,2%min%H:~6,2%s)
If Not Exist HISTO\ MD HISTO
Type *.txt>>"HISTO\cli_%DH: =%.txt"
Move *.txt HISTO
Copy "HISTO\cli_%DH: =%.txt" "%BD%\cli.txt"
Maybe COPY could prove a better solution than TYPE and also if you want the cli.txt to be included as part of the next run, then you may need to ensure that it is named in such a way as to be the first one typed from the wildcard, perhaps naming it _cli.txt may be sufficient.

Post Reply