ATTN: Robert B. Clark re: Delete file body, leave file name?

C

Captain Infinity

In Message-ID: <[email protected]>
Robert B. Clark said:
The line

REM>filename

will overwrite filename with a zero-byte file of the same name--truncates
it, IOW.

Here is a batch file I call ZERO.BAT that is built around this trick:

:: Truncates all specified files in cwd to 0-byte files.
:: R Clark 18 Dec 2003
::
@echo off
%comspec% /c %temp%\$foo1.bat > %temp%\$foo2.bat

:: Change filespec in parentheses below to whatever you need
for %%a in (*.bak) do call %temp%\$foo2 %%a

:: Clean up
for %%a in (%temp%\$foo?.bat) do del %%a>NUL

Of course, if you change the filespec so that it includes ZERO.BAT and the
batch file is in the current working directory, you'll have a spot of
trouble. :)

This worked well in Windows 98. Is there a tweak I need to make to get
it to work in XP? Perhaps something relating to the %temp% setting? I
notice the *foo* files are being created in
c:\documents and settings\owner\local settings\temp and that the cleanup
is not happening. Is this important? Or does the REM>filename command
just not work in XP? If not, is there something similar, or perhaps a
utility that will allow for mass overwriting of files in a way that
leaves the filenames?

TIA.


**
Captain Infinity
 
R

Robert B. Clark

This worked well in Windows 98. Is there a tweak I need to make to get
it to work in XP? Perhaps something relating to the %temp% setting? I
notice the *foo* files are being created in
c:\documents and settings\owner\local settings\temp and that the cleanup
is not happening. Is this important? Or does the REM>filename command
just not work in XP? If not, is there something similar, or perhaps a
utility that will allow for mass overwriting of files in a way that
leaves the filenames?

Running the batch file as-is under WinXP presents several problems:

1. The TEMP evar likely contains a long file spec; e.g.,

Temp=C:\Documents and Settings\Administrator\Local Settings\Temp

This will break the batch file since the temp file specs now contain
spaces. The solution is to either enclose the LFN specs with quotation
marks, or simply temporarily set TEMP to some legal SFN.


2. The construct

REM>filename

apparently does not work under WinXP. The construct

type NUL>filename

does work, however.


3. For whatever reason, the line

%comspec% /c %temp%\$foo1.bat > %temp%\$foo2.bat

is not working as expected, even after the other problems have been
corrected. I have been unable to determine why this is so. Perhaps
someone else can chime in here--I am quite proficient with DOS batch files,
but have not done much at all with NT batch files.

HOWEVER. the batch file does work as expected if you use COMMAND.COM
instead of CMD.EXE as the command processor.

Taking all of the above into account, here is a modified version of
ZERO.BAT that works under WinXP:

:: Truncates all specified files in cwd to 0-byte files.
:: WINXP VERSION
:: R Clark 26 Jan 2004
::
@echo off
:: Save org evars. Adjust paths as required.
set t=%temp%
set cs=%comspec%
set temp=C:\Temp
set comspec=command.com

:: Second line below does not work if COMSPEC=CMD.EXE
%temp%\$foo1.bat echo @prompt type NUL$g%%%%1
%temp%\$foo2.bat %comspec% /c %temp%\$foo1

:: Change filespec in parentheses below to whatever you need
for %%a in (*.bak) do call %temp%\$foo2 %%a

:: Clean up
set temp=%t%
set comspec=%cs%

for %%a in (%temp%\$foo?.bat) do del %%a>NUL
for %%a in (t cs) do set %%a=

Hope this helps.
 
C

Captain Infinity

Once Upon A Summertime, Just A Dream From Yesterday
Robert said:
3. For whatever reason, the line

%comspec% /c %temp%\$foo1.bat > %temp%\$foo2.bat

is not working as expected, even after the other problems have been
corrected. I have been unable to determine why this is so. Perhaps
someone else can chime in here--I am quite proficient with DOS batch files,
but have not done much at all with NT batch files.

HOWEVER. the batch file does work as expected if you use COMMAND.COM
instead of CMD.EXE as the command processor.

Taking all of the above into account, here is a modified version of
ZERO.BAT that works under WinXP:

:: Truncates all specified files in cwd to 0-byte files.
:: WINXP VERSION
:: R Clark 26 Jan 2004
::
@echo off
:: Save org evars. Adjust paths as required.
set t=%temp%
set cs=%comspec%
set temp=C:\Temp
set comspec=command.com

:: Second line below does not work if COMSPEC=CMD.EXE

This step is giving me an "out of environment space" error.
:: Change filespec in parentheses below to whatever you need
for %%a in (*.bak) do call %temp%\$foo2 %%a

The call is giving me the error "the syntax of the command is
incorrect". The batch file then quits.
:: Clean up
set temp=%t%
set comspec=%cs%

for %%a in (%temp%\$foo?.bat) do del %%a>NUL
for %%a in (t cs) do set %%a=

Hope this helps.

I appreciate your help with this, thank you.


**
Captain Infinity
 
R

Robert B. Clark

Once Upon A Summertime, Just A Dream From Yesterday


This step is giving me an "out of environment space" error.

Either increase your environment space, or hard-code the evars; e.g.,

replace all %temp% with C:\Temp
replace all %comspec% with CMD.EXE (or COMMAND.COM)

Delete the lines above where %t%, %temp% and %cs% were assigned, and remove
the lines at the end of the batch (in the Clean up section) where the
environment variables were restored.
The call is giving me the error "the syntax of the command is
incorrect". The batch file then quits.

This is because your %temp% evar was either truncated or missing, due to
insufficient environment space.
 
C

Captain Infinity

3. For whatever reason, the line
Either increase your environment space, or hard-code the evars; e.g.,

replace all %temp% with C:\Temp
replace all %comspec% with CMD.EXE (or COMMAND.COM)

Delete the lines above where %t%, %temp% and %cs% were assigned, and remove
the lines at the end of the batch (in the Clean up section) where the
environment variables were restored.


This is because your %temp% evar was either truncated or missing, due to
insufficient environment space.

Robert, I truly appreciate all the help with this program, but I just
cannot get it to work, mainly due to my lack of technical expertise. I
don't know how to increase my environment space, and hard-coding the
evars results in the creation of zero-bit files with names that are just
the first letter of the files in the directory. That is, in a folder
with a dozen files named File01.mpg, File02.mpg, File03.mpg and so on, a
single zero-bit file named F is created. All the original files are
untouched.

I've thrown pauses between each of the steps and turned echo back on so
I can see what is happening, and it looks like it wants to work, but I
still get this odd result.

Anyway, unless you can think of a quick fix for my situation, don't
worry about it. Re-sizing the files to zero-bit was just a passing
fancy of mine, a way of getting out of some other work (that of tracking
whether I need to add new files to get a complete collection of mp3's,
once they've been moved to CD). I'll just have to overcome my laziness
and throw the CD into the drive to check its contents.

Thanks again for your help.


**
Captain Infinity
 
R

Robert B. Clark

Robert, I truly appreciate all the help with this program, but I just
cannot get it to work, mainly due to my lack of technical expertise. I
don't know how to increase my environment space, and hard-coding the
evars results in the creation of zero-bit files with names that are just
the first letter of the files in the directory. That is, in a folder
with a dozen files named File01.mpg, File02.mpg, File03.mpg and so on, a
single zero-bit file named F is created. All the original files are
untouched.

Please post the latest version of your batch file. I'll check it over and
see where the problem might be.
 
C

Captain Infinity

Once Upon A Summertime, Just A Dream From Yesterday
Robert said:
Please post the latest version of your batch file. I'll check it over and
see where the problem might be.

---------------------------------------------------------------
:: Truncates all specified files in cwd to 0-byte files.
:: WINXP VERSION
:: R Clark 26 Jan 2004
::
:: @echo off
:: Save org evars. Adjust paths as required.
:: set t=%temp%
:: set cs=%comspec%
:: set temp=C:\Temp
:: set comspec=command.com

:: Second line below does not work if COMSPEC=CMD.EXE
C:\Temp\$foo1.bat echo @prompt type NUL$g%%%%1 pause
C:\Temp\$foo2.bat command.com /c C:\Temp\$foo1
pause

:: Change filespec in parentheses below to whatever you need
for %%a in (*.mp3) do call C:\Temp\$foo2 %%a
pause

:: Clean up
:: set temp=%t%
:: set comspec=%cs%

:: for %%a in (%temp%\$foo?.bat) do del %%a>NUL
:: for %%a in (t cs) do set %%a=
 
R

Robert B. Clark

Once Upon A Summertime, Just A Dream From Yesterday

Ah! The files you are truncating have long file names!
---------------------------------------------------------------
:: Truncates all specified files in cwd to 0-byte files.
:: WINXP VERSION
:: R Clark 26 Jan 2004
::
:: @echo off
:: Save org evars. Adjust paths as required.
:: set t=%temp%
:: set cs=%comspec%
:: set temp=C:\Temp
:: set comspec=command.com

:: Second line below does not work if COMSPEC=CMD.EXE
pause

:: Change filespec in parentheses below to whatever you need
for %%a in (*.mp3) do call C:\Temp\$foo2 %%a

Change the preceding line to
for %%a in (*.mp3) do call C:\Temp\$foo2 "%%a"

Note the quotation marks around the parameter to the $foo2.bat call.

<snip>
 
C

Captain Infinity

Once Upon A Summertime, Just A Dream From Yesterday
Robert said:
Ah! The files you are truncating have long file names!

Yes. Also, they contained spaces, periods, and commas. When I removed
these items, the batch file worked perfectly. Thanks again for your
help, this little proggy is great.


**
Captain Infinity
 
Top