Solved

Batch File to clean contents on a shared Folder.

Posted on 2012-03-18
10
370 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 84

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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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
 

Author Comment

by:chinniatluri
ID: 37736655
oBdA,

 Any VBscript that does with same functionality
0
 
LVL 84

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 84

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

752 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