Solved

Batch File to clean contents on a shared Folder.

Posted on 2012-03-18
10
351 Views
Last Modified: 2012-03-19
I need a batch file which can do the job of mapping a shared network folder & clearing the contents of the shared folder.

It would be helpful if you can provide the VB script for the same.
0
Comment
Question by:chinniatluri
  • 6
  • 3
10 Comments
 
LVL 8

Expert Comment

by:PeteEngineer
ID: 37736464
This article helps you to map a network drive :

https://msmvps.com/blogs/kwsupport/archive/2004/11/03/17830.aspx

Clearing its just removing command in the batch..

Good luck !

-Pete
0
 

Author Comment

by:chinniatluri
ID: 37736507
what is the command to remove fiels?
0
 
LVL 83

Expert Comment

by:oBdA
ID: 37736546
Here's a little batch script; if it's really just about deleting the folder, there's no need to map a drive, you can just use a UNC path.
Save this as Whatever.cmd; the script is currently in test mode and will only display the delete commands it would normally run. It will first delete all files in the folder specified, then all subfolders. Remove the uppercase "ECHO"s to run it for real.
@echo off
setlocal
set Folder=\\SomeServer\SomeShare\SomeFolder
for %%a in ("%Folder%\*.*") do (
  ECHO del "%%~a"
)
for /d %%a in ("%Folder%\*.*") do (
  ECHO rd /s /q "%%~a"
)

Open in new window

0
 

Author Comment

by:chinniatluri
ID: 37736569
I had modified the script as below :
@echo off
setlocal
set Folder=\\192.168.1.22\da$
for %%a in ("%Folder%\*.*") do (
 
)
for /d %%a in ("%Folder%\*.*") do (
 
)
             


While running I'm getting ) was unexpected at this time
0
 

Author Comment

by:chinniatluri
ID: 37736574
@echo off
setlocal
set Folder=\\192.168.1.22\da$
for %%a in ("%Folder%\*.*") do (
   del "%%~a"
)
for /d %%a in ("%Folder%\*.*") do (
   rd /s /q "%%~a"
)

This done the job for me ! If you dont mind can you give a brief of each line, about what it does?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:chinniatluri
ID: 37736655
oBdA,

 Any VBscript that does with same functionality
0
 
LVL 83

Expert Comment

by:oBdA
ID: 37736709
As for what the batch script does:
for %%a in ("%Folder%\*.*") do (
   del "%%~a"
)

That's a standard "for" loop over all files in the directory that's defined in the variable "folder"; in the loop, the currently processed file can be referenced using the loop variable "%%a".

for /d %%a in ("%Folder%\*.*") do (
   rd /s /q "%%~a"
)

Basically the same as above, but with the option "/d" to process directories instead of files.
rd /s /q "%%~a" will then delete the currently processed directory quietly (/q), including all subfolders (/s).
0
 

Author Comment

by:chinniatluri
ID: 37736732
oBdA,

Thanks for the explanation. Any VBscript that does work with same functionality, Please let me know?
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 37739951
Try this; it's in test mode and will display the files and folders it would delete.
Remove the "comment" apostrophe to run it for real.
To avoid a popup box for each file/folder, either run it with cscript.exe, or comment out the "Wscript.Echo" lines.
strFolder = "\\SomeServer\SomeShare\SomeFolder"
Set fso = CreateObject("Scripting.FileSystemObject")
For Each objFile In fso.GetFolder(strFolder).Files
  Wscript.Echo "Deleting file: " & objFile.Path
'  objFile.Delete
Next
For Each objSubfolder In fso.GetFolder(strFolder).Subfolders
  Wscript.Echo "Deleting folder: " & objSubfolder.Path
'  objSubfolder.Delete
Next

Open in new window

0
 

Author Closing Comment

by:chinniatluri
ID: 37740762
ObDa Thanks for the Help & timely response
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now