Solved

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

Posted on 2008-10-14
5
608 Views
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.

Pawel
0
Comment
Question by:Pawel-Blazejewicz
  • 2
  • 2
5 Comments
 
LVL 31

Expert Comment

by:James Murrell
ID: 22710244
something like

@echo off

:delete
net use h: /delete
if errorlevel 1 goto delete

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

:success
echo Remapping of H: successfully completed.


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

Author Comment

by:Pawel-Blazejewicz
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.

0
 
LVL 31

Expert Comment

by:James Murrell
ID: 22710367
0
 
LVL 28

Accepted Solution

by:
Bill Bach earned 125 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: /DELETE
   NET USE X: \\Server\Share
   X:
   CD \Folder2
   DEL *.*
0
 

Author Closing Comment

by:Pawel-Blazejewicz
ID: 31505828
Thank you
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Even if you have implemented a Mobile Device Management solution company wide, it is a good idea to make sure you are taking into account all of the major risks to your electronic protected health information (ePHI).
If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

803 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