Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Automatically Delete Files In A Directory

Posted on 2007-11-19
14
Medium Priority
?
829 Views
Last Modified: 2010-04-21
I have a shared folder on one of our servers (Windows 2003 Server Enterprise) for our patrons to temporarily store files in case they don't have their flash drive with them.  In the past with our old server (ie, before I was here) the shared folder was emptied every night around 11pm by some automatic process.  I cannot find any info on how it was done before I got here so I am throwing it out to the Experts.

The only issue is that users can create files or folders.  We want to clear everything out, but there is always one folder we want to show up (let's call it "files"for this senario).  I don't mind if the process is to clear out everything in the folder and recreate the "files" folder (there shouldn't be anything inside of it anyways).  But the process does need to run independent of user interaction though.

So I am open to a script and scheduled task, or a software application, whatever will be simple and easy to implement.  Thanks!!
0
Comment
Question by:parkridgelibrary
[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
  • 7
  • 7
14 Comments
 
LVL 9

Accepted Solution

by:
MSE-dwells earned 2000 total points
ID: 20314531
I'd suggest you schedule a task on the server holding the share that runs at the desired time, the task syntax would look something like this -

cmd /c rd /s /q <your path here> && md <your path here>\Files

... you may also need to schedule the task to run as a particular user depending upon the NTFS permissions configured on the directory.

Note - that is a very destructive command so please be careful!
0
 

Author Closing Comment

by:parkridgelibrary
ID: 31409997
Absolutely perfect!! THANK YOU SO MUCH!!!
0
 

Author Comment

by:parkridgelibrary
ID: 20350124
Hey MSE-dwells,

The code you gave me above seems to be working except only parially.  Here are the two schedule tasks I made:

- C:\WINDOWS\system32\cmd.exe /c rd /s /q K:\Patron_Temp && md K:\Patron_Temp\"IMPORTANT - All files saved here are viewable by everyone and are deleted daily !!"

- C:\WINDOWS\system32\cmd.exe /c rd /s /q k:\Patron_CS_Temp && md k:\Patron_CS_Temp\"IMPORTANT - All files saved here are viewable by everyone and are deleted daily !!"

The second one works perfectly, but the first one seems to only half work.  It will clear out all of the files, but it does not create the new folder.  When I looked at the Scheduled Tasks section, it showed a Last Result of 0x20 for the first one.  When I tried to look up what that means, it look like it means either "The system cannot find the device specified" or "User limit exceeded".

Neither of these makes much sense to me.  Can you tell me what I am missing or if I didn't get the code right?  My other thought was to make a *.bat file with these commands in them so that there is only one scheduled task.  However when I tried that and ran it in the Command Window to see the result it said "The process cannot access the file because it is being used by another process."  Any ideas?
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20350175
My first suggestion would  be to place the quotes differently, see below -

C:\WINDOWS\system32\cmd.exe /c rd /s /q K:\Patron_Temp && md "K:\Patron_Temp\IMPORTANT - All files saved here are viewable by everyone and are deleted daily !!"

C:\WINDOWS\system32\cmd.exe /c rd /s /q k:\Patron_CS_Temp && "md k:\Patron_CS_Temp\IMPORTANT - All files saved here are viewable by everyone and are deleted daily !!"

... as for the error, let's first see what we get when using this syntax.
0
 

Author Comment

by:parkridgelibrary
ID: 20381293
MSE-dwells,

Changing the quotes definitely helped.  The only problem I am running into now, is that when it runs it seems to reset the sharing and security permissions.  Or something else is, but it never happened before I tried the script.  Any thoughts?
0
 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20381336
What directory(ies) is/are shared?  Which permissions are disappearing -- NTFS or share?
0
 

Author Comment

by:parkridgelibrary
ID: 20381625
The k:\Patron_CS_Temp and k:\Patron_Temp folders are shared.  When I check it this morning though, only the k:\Patron_Temp had missing permissions.  The other one was fine.
0
 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20381733
Which permissions?  NTFS?  Are they still shared?
0
 

Author Comment

by:parkridgelibrary
ID: 20381755
The permissions for like READ/WRITE/ETC.  In one case the accounts that were added in to have access were removed completely.  But yes, they are still shared as not all of the accounts were removed.
0
 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20381785
Unfortunately, you're not answering my question ... I could take a guess but I'd prefer to be certain.  Which tab are you using in Windows Explorer to determine that the permissions have either been removed or are still present?
0
 

Author Comment

by:parkridgelibrary
ID: 20382012
Sorry, I don't think I fully understood what you were asking (and I am not feeling well, so my brain isn't fully functional at the moment).  I looking at both the sharing and the security tabs when I right-click the folder and choose properties.
0
 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20382098
Feeling sick has the same effect on me :0(

The issue with sharing shouldn't occur since the folder is recreated almost immediately because the sharing configuration and its permissions aren't part of the filesystem ... can I presume that the shares do indeed persist each night along with their permissions?

Now, the NTFS pemissions are an entirely different story.  I confess I hadn't considered that each folder would be using a customized ACL -- not that it's wrong, it's just less common than relying upon inheritance.  We may need to alter the solution slightly to account for this -

C:\WINDOWS\system32\cmd.exe /c pushd K:\Patron_Temp && rd /s /q . & md "IMPORTANT - All files saved here are viewable by everyone and are deleted daily !!" & popd

C:\WINDOWS\system32\cmd.exe /c pushd K:\Patron_CS_Temp && rd /s /q . & md "IMPORTANT - All files saved here are viewable by everyone and are deleted daily !!" & popd

... as always, these commands are MASSIVELY DESTRUCTIVE, please test them first to your own satisfaction (I did the same but don't take my word for it ;0)
0
 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20382115
... minor verbiage correction -

"The issue with sharing shouldn't occur since the folder is recreated almost immediately *and* because the sharing configuration and its permissions aren't part of the filesystem ..."
0
 

Author Comment

by:parkridgelibrary
ID: 20382157
Yes the shares do show up continually and the inherited permissions show up just fine.  The other permissions I am adding are to allow an additional group to have access to the folder who does not have access to anything above it.  I personally would never setup a file structure in this manner, but it was in place before I was working here and I am not sure if it is worth trying to move it at this point.  I will try your new suggestions and let you know how it goes.  Thanks!!
0

Featured Post

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.

Question has a verified solution.

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

Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 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