Computing.Net > Forums > Programming > Need batch file help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need batch file help

Reply to Message Icon

Name: bryan6565
Date: October 21, 2008 at 15:01:34 Pacific
OS: XP
CPU/Ram: 2.4Ghz P4/1GB DDR
Product: Dell Inspiron 530
Comment:

I have a problem. I am trying to write a batch file which will delete a 0 KB .SPL file and an associated .SHD file, which is not 0 KB. Each .SHD file has the exact filename as the .SPL file, for example: 00001.SPL and 00001.SHD. If 00001.SPL is 0 KB, I want the batch file to delete 00001.SPL and 00001.SHD, regardless of the size of 00001.SHD. What I have so far only deletes the .SPL files. This is what I have to execute the deletion of the .SPL file:

for %%f in ("C:\directorypath\*.spl") do if %%~zf == 0 del %%f

I know I need to assign some variables to pull this off, but I'm not that handy with batch files. Any help will be appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: pball
Date: October 21, 2008 at 19:23:14 Pacific
Reply:

for %%f in ("C:\directorypath\*.spl") do (
if %%~zf == 0 (
del %%f
del %%~nf.shd
)
)

the %%~nf should get you just the file name without the extension and the .shd is the extension.

tested and it works


0

Response Number 2
Name: bryan6565
Date: October 21, 2008 at 19:52:26 Pacific
Reply:

No luck with that. It still left the .SHD file even though it successfully deleted the 0 KB .SPL file. I'm uploading an image of the files in the directory to better describe the issue at hand. I'm wanting the batch file to delete the files with the red boxes around them.


0


Response Number 3
Name: bryan6565
Date: October 21, 2008 at 19:56:29 Pacific
Reply:

Sorry, the picture is located at http://img296.imageshack.us/img296/...

For some reason, the Image URL box at the bottom didn't load the image for me.


0


Response Number 4
Name: klint
Date: October 22, 2008 at 01:53:32 Pacific
Reply:

I can see what the problem is. Change the line

del %%~nf.shd


to

del C:\directorypath\%%~nf.shd


0

Response Number 5
Name: pball
Date: October 22, 2008 at 04:45:54 Pacific
Reply:

Whoops I forgot about the directory since I just tested the batch in the same folder.

Thanks klint for pointing that out


0

Related Posts

See More



Response Number 6
Name: bryan6565
Date: October 22, 2008 at 05:05:33 Pacific
Reply:

I'm actually excited to go to work today to try this out! I'll let you know how it goes, thanks for the help.


0

Response Number 7
Name: pball
Date: October 22, 2008 at 06:27:01 Pacific
Reply:

I'm glad your excited to go to work, cause I know I'm never excited to go to work


0

Response Number 8
Name: bryan6565
Date: October 22, 2008 at 06:30:30 Pacific
Reply:

It works! Thanks pball and klint for taking the time to help me out.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Need batch file help

Batch file help needed www.computing.net/answers/programming/batch-file-help-needed/13589.html

batch file help www.computing.net/answers/programming/batch-file-help/13830.html

Batch File Help www.computing.net/answers/programming/batch-file-help-/11464.html