General discussion

Locked

Automatically search and delete files?

By brett.maltbie@st-francis ·
I would like to automate file deletion across different folders/subfolders. There are a couple of situations where this would be handy:

1) deleting all the leftover ~*.* files from all my user shares on my file server.

2) deleting all the temporary internet files from all my user profiles. (running NT4 terminal services - I can get much quicker login times if I keep the profiles small.)

In each case, the paths for a given deletion would be congruent, i.e. for 1), the path would always be \\fileserver\%username%\personal\ then I would want to del ~*.* for 2), the path would be \\fileserver\profiles\%username%\tempor~1\ then I would del *.*

I tried making a .bat file and then calling the variable %username% from a text file, but the text file was too big once I got all my usernames in there.

Any suggestions?

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Automatically search and delete files?

by BeerMonster In reply to Automatically search and ...

Hi,
I'd try the username process 'in reverse'. judging by what you wrote, each users profile directory is a share - IE accessible via

\\server\%username%

You can enumerate all shares via the NET SHARE
command. So, we could say
for /f %Ain ('net share') do echo %A

Note that in a batch file you will need to put an extra % in front of %A. the snippet above loops through the output of the net share command and sets %A to each sharename in turn. next, I would use the net user username /domain

command, to check whether the folder name tallied with a domain user, if it did, then I'd go on with the delete statements within that folder. Note that the /domain command above does not need to be changed to your domain name, it's simply tellint the net user command to check on the domain rather than the local machine. The end result would be something like -


for /f %%A in ('net share') do call :go %%A
goto end

:go

net user %1 /domain | find /I "The user name could not be found"
If %errorlevel%==0 goto end
...your delete statements would go here.
:end

I've written the above 'off the cuff' so obviously it needs testing. Hope this helps....

Collapse -

Automatically search and delete files?

We need more options than just "acceptable" or "unacceptable."
It seems ungrateful. This was a great response, but only partially helpful. To leave the question open I have to call your answer "unacceptable." Sorry, BeerMonster

Collapse -

Automatically search and delete files?

My profiles folders aren't shares - they all reside together in a common share, so this won't help situation (2). But each user's data folder is it's own share, so your answer may solve situation (1). I must admit your answer is over my head, so I'll have to do some studying before I can test it. But thank you for the lesson.

Collapse -

Automatically search and delete files?

by BeerMonster In reply to Automatically search and ...

Hi,
So, any reason why you can't use a

dir /b

in your share to get a list of all the folders, then pass that to the net user command ?

Back to Windows Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums