Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delete Public Drive on a daily schedule

Posted on 2015-02-17
13
Medium Priority
?
81 Views
Last Modified: 2015-02-18
I created this script to delete a map drive every 3 AM, but for some reason it won't delete the folders and subfolders.

This is the script I created.

Echo ================================================================= >> Arquivos_deletados.txt
date /t >> arquivos_deletados.txt 
time /t >> arquivos_deletados.txt 
Echo ================================================================= >> Arquivos_deletados.txt
del D:\Shared~1\Public /F/s/q >> Arquivos_deletados.txt
rmdir D:\Shared~1\Public /s/q 
mkdir D:\Shared~1\Public

Open in new window

0
Comment
Question by:cinco-pata5
[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
  • 8
  • 3
  • 2
13 Comments
 
LVL 25

Expert Comment

by:NVIT
ID: 40614994
Does it work manually?

Are you calling this .bat from task scheduler?
0
 

Author Comment

by:cinco-pata5
ID: 40615097
I tried, it says "Access denied the file is being used by another process."  The problem is that I rebooted the server, but it still comes with that message.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40615240
Where is your file "Arquivos_deletados.txt" located? If it's on the same location as  D:\Shared~1\Public you will get that error message because the del command is both writing to a file in the folder it is trying to delete. For testing, try this:

Echo ================================================================= >> c:\temp\Arquivos_deletados.txt
date /t >> c:\temp\arquivos_deletados.txt 
time /t >> c:\temp\arquivos_deletados.txt 
Echo ================================================================= >> c:\temp\Arquivos_deletados.txt
del D:\Shared~1\Public /F/s/q >> c:\temp\Arquivos_deletados.txt
rmdir D:\Shared~1\Public /s/q 
mkdir D:\Shared~1\Public

Open in new window


This assuming you have a c:\temp folder that you can write to.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:cinco-pata5
ID: 40615261
I did the modification, but it still comes with access denied.  I tried manually deleting the files, and copying another but it still has the permission issue.
0
 

Author Comment

by:cinco-pata5
ID: 40615265
I can only have a successful outcome with running as an administrator permissions, but I wanted to be able to delete it without the elevated permissions.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40615274
>> but I wanted to be able to delete it without the elevated permissions.
But a public drive is written to by users other than yourself, right? That means that you should delete these files as administator anyway.
0
 

Author Comment

by:cinco-pata5
ID: 40615304
This is what I'm getting, I'm attaching a screen shot to show.  In the script I end up deleting the folder and recreating, but this folder has a sharing permissions, I'm not sure if it has something to do with it?
0
 

Author Comment

by:cinco-pata5
ID: 40615308
Screenshot
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40615383
The second error message is because the folder could not be removed.  I've tested the same and it works, can you try instead: "rmdir /s /q d:\shared~1\public" or "rmdir /s /q ..\shared~1\public"

Why would you want to remove the directory and recreate it btw? The del command is already deleting every file in it so you could just leave out the rmdir/mkdir commands, right?
0
 

Author Comment

by:cinco-pata5
ID: 40615406
I'll try, the rmdir I actually got this script from somebody, but it does make sense why should I have to remove the folder and recreate it.
0
 

Author Comment

by:cinco-pata5
ID: 40615430
I got it to work, but for some reason it dosen't delete the sub-folders in the folder.  Even with the /F/S command.
0
 
LVL 25

Accepted Solution

by:
NVIT earned 2000 total points
ID: 40615840
If you're trying to remove sub-folders with DEL /F /S, you can't. I guess that's why you have the next line RMDIR.

Maybe you can't delete Public because it's the top folder and its protected. Still, you could DEL the Public files and sub-folders with RMDIR alone:
for /d %%a in (d:\shared~1\public\*) do rmdir /s /q "%%a"

Open in new window

0
 

Author Closing Comment

by:cinco-pata5
ID: 40616253
It worked.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

618 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