cinco-pata5
asked on
Delete Public Drive on a daily schedule
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.
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
ASKER
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.
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:
This assuming you have a c:\temp folder that you can write to.
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
This assuming you have a c:\temp folder that you can write to.
ASKER
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.
ASKER
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.
>> 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.
But a public drive is written to by users other than yourself, right? That means that you should delete these files as administator anyway.
ASKER
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?
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?
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?
ASKER
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.
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It worked.
Are you calling this .bat from task scheduler?