Cannot copy file in spite of size file fits space available?

J

Joachim Hofmann

Hello,

I have a batch file which does some copy jobs nightly.

I wish to copy a file only if there is enough space, otherwise I wish to delete
some other file(s).

I get the size of the file to be copied by the for...%~zI - clause.
DIR gives me the free disk space into another variable.

Now I compare these values (and redirect the output into a logfile).
========================================================================

Result of the *first* copy job:
disk free: 33013485568
file size: 18418023936

Result message of copy: "Network is not available any more"

Result of the *following* copy job:

disk free: 24847392768
file size: 18418023936

Result message of copy: "Not enough space available"


The *following* job (3037577216, 77614592) however succeeded as I expected.

========================================================================

Whats wrong, any hints?

Thank You

Joachim

[Windows 2000 Server]
 
P

Pegasus \(MVP\)

Joachim Hofmann said:
Hello,

I have a batch file which does some copy jobs nightly.

I wish to copy a file only if there is enough space, otherwise I wish to
delete
some other file(s).

I get the size of the file to be copied by the for...%~zI - clause.
DIR gives me the free disk space into another variable.

Now I compare these values (and redirect the output into a logfile).
========================================================================

Result of the *first* copy job:
disk free: 33013485568
file size: 18418023936

Result message of copy: "Network is not available any more"

Result of the *following* copy job:

disk free: 24847392768
file size: 18418023936

Result message of copy: "Not enough space available"


The *following* job (30 37 577 216, 77 614 592) however succeeded as I
expected.

========================================================================

Whats wrong, any hints?

Thank You

Joachim

Let's have a look at your batch file.
Also: Have you tried copying your files manually? If yes, by what method?
 
J

Joachim Hofmann

Pegasus said:
Have you tried copying your files manually? If yes, by what method?

Not so easy to reproduce by day.
This special case normally only happens on a Saturday, when the Admin was not
present to delete old files manually, so that on this day there is less disk
space.
On Mo-Fr, when there is more space, it works.

Example:
disk free: 66381103104
file size: 30682228224
-> copy ok

So I thought it could be a difference between actual disk space and calculated
disk space.
Let's have a look at your batch file.

1 FOR /F "usebackq" %%F in (`DIR %BasePath% /AD /B`) DO (
2 FOR /F "usebackq tokens=2 delims= " %%D IN (`DATE /t`) DO (
4 FOR %%B IN (%BasePath%%%F\%Filemask%) DO (
5 ECHO Backup: %%~nxB to %%~nB_%%D%%~xB... >> logfile.log
6 ECHO Comparing free disc space and file size ...
7 FOR /F "usebackq tokens=3 delims=, " %%I IN (`DIR /-c ^| findstr "Bytes.frei"`) DO (
8 IF %%~zB GTR %%I (
9 ECHO No space -%%I- for file -%%~zB- , deleting existing file before copying new one10 DEL %ZielMandantPfad%%%F\%%i >> logfile.log 2>&1
11 ) ELSE (
12 ECHO Space enough -%%I- for file -%%~zB- >> logfile.log
13 ))
14 COPY %%B %ZielMandantPfad%%%F\%%~nB_%%D%%~xB >> BefehlsausgabenVoll.log 2>&1
15 ...


In 4 I get the file name into %%B
In 7 I put the "Bytes free" output into %%I
In 8 I compare these two values to decide what to do: deleting existing file or
not

Hmm.. as I write this, I notice that in 10 I am using %%i, I think it should be
%%B; %%i is a size variable.

I will change that and watch what the job does.

Joachim
 
P

Pegasus \(MVP\)

Joachim Hofmann said:
Not so easy to reproduce by day.
This special case normally only happens on a Saturday, when the Admin was
not
present to delete old files manually, so that on this day there is less
disk
space.
On Mo-Fr, when there is more space, it works.

Example:
disk free: 66381103104
file size: 30682228224
-> copy ok

So I thought it could be a difference between actual disk space and
calculated
disk space.


1 FOR /F "usebackq" %%F in (`DIR %BasePath% /AD /B`) DO (
2 FOR /F "usebackq tokens=2 delims= " %%D IN (`DATE /t`) DO (
4 FOR %%B IN (%BasePath%%%F\%Filemask%) DO (
5 ECHO Backup: %%~nxB to %%~nB_%%D%%~xB... >> logfile.log
6 ECHO Comparing free disc space and file size ...
7 FOR /F "usebackq tokens=3 delims=, " %%I IN (`DIR /-c ^| findstr
"Bytes.frei"`) DO (
8 IF %%~zB GTR %%I (
9 ECHO No space -%%I- for file -%%~zB- , deleting existing
file before copying new one
10 DEL %ZielMandantPfad%%%F\%%i >> logfile.log 2>&1
11 ) ELSE (
12 ECHO Space enough -%%I- for file -%%~zB- >> logfile.log
13 ))
14 COPY %%B %ZielMandantPfad%%%F\%%~nB_%%D%%~xB >>
BefehlsausgabenVoll.log 2>&1
15 ...


In 4 I get the file name into %%B
In 7 I put the "Bytes free" output into %%I
In 8 I compare these two values to decide what to do: deleting existing
file or
not

Hmm.. as I write this, I notice that in 10 I am using %%i, I think it
should be
%%B; %%i is a size variable.

I will change that and watch what the job does.

Joachim

No, %%i is not a size variable, it is nothing because it is in lower case.
Your code does not appear to set it in any way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top