A batch file to delete files from a network share... ?

Posted on 2008-10-14
Medium Priority
Last Modified: 2012-05-05
Hi experts,

I have a quick question. I need a batch file to delete files from a network share. I tried mapping the drive as f.e. letter X: than cd x:\filder   but it just does not want to work for me.
Is there some other way of doing that ? First option (mapping and logging in i was able to manage but cannot sort this issue out)

Thank you for your help.

Question by:Pawel-Blazejewicz
  • 2
  • 2
LVL 31

Expert Comment

by:James Murrell
ID: 22710244
something like

@echo off

net use h: /delete
if errorlevel 1 goto delete

net use h: \\server\share
if errorlevel 1 goto map

echo Remapping of H: successfully completed.

taken from http://www.hardforum.com/archive/index.php/t-1048024.html

Author Comment

ID: 22710355
Hi there, thanks for your fast answer but what I am looking for i a way of deleting files stored on the netowrk share not the share itself. Lest say I have \\server\folder\folder2\files   and I want to delete all files stored on Folder2 using a batch file or a windows script does not matter how to be honest, just something that will do this job for me.

LVL 31

Expert Comment

by:James Murrell
ID: 22710367
LVL 29

Accepted Solution

Bill Bach earned 500 total points
ID: 22710459
The problem is in your CD command, which cannot change both the drive and path at the same time.

The right way is this:
   NET USE X: \\Server\Share
   CD \Folder2
   DEL *.*

Author Closing Comment

ID: 31505828
Thank you

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this article, the configuration steps in Zabbix to monitor devices via SNMP will be discussed with some real examples on Cisco Router/Switch, Catalyst Switch, NAS Synology device.
If you try to migrate from Elastix to Issabel, you will face a lot of issues. These problems are inevitable but fortunately, you can fix them. In the guide below, I will explain how I performed the migration while keeping all data and successfully t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question