Solved

Search multiple folders in windows

Posted on 2012-03-19
7
301 Views
Last Modified: 2012-03-20
We have our users personal drives stored on one server. Each user has a top level folder named for their username. Within this they store their files, and also their roaming profile. I would like to search within the username\profile\cookies folder to find files older than a specific date (to delete)
How can is seach just the muliple cookies folders to find these files?
0
Comment
Question by:SYPTE-IT
[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
  • 3
  • 2
  • 2
7 Comments
 

Expert Comment

by:TwynFeyr
ID: 37739343
VB script would probably be the easiest.  Kind of like this:

'------------------------------------------------------------
' Root folder
strRoot= "C:\temp\"
' The common subfolder for each directory
CommonSubFolder="\profile\Cookies"
' maximum file age in days
maxFileAge = 5

' With the current settings this will delete all files equal to or older than 5 days
' in the sub folder \profile\cookies\ for each Sub directory of c:\temp
'
' E.g.
' c:\temp\user1\profiles\cookies
' c:\temp\user2\profiles\cookies
'------------------------------------------------------------


set objFSO = createobject("Scripting.FileSystemObject")

set objFolders = objFSO.GetFolder(strRoot)

for each strFolderName in objFolders.SubFolders
      if objFSO.Folderexists(strFolderName + CommonSubFolder) then
            DeleteFiles strFolderName.path + CommonSubFolder, maxFileAge
      end if
next

sub DeleteFiles(strDirectory,maxAge)
      set objFolder = objFSO.GetFolder(strDirectory)
      for each objFile in objFolder.Files
            IF objFile.DateLastModified <= (Now - MaxAge) THEN
                  objFile.Delete
            END IF
      next      
end sub

'------------------------------------------------------------
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37740145
Questions

1) Can you confirm your folder structure:

if your servername is 'Server' and,
if your driveletter is 'C:' and,
if you have say, 3 users 'Tom', 'Dick' and 'Harry' then,
is the following structure correct?

    \\Server\$C\Tom\profile\cookies\
    \\Server\$C\Dick\profile\cookies\
    \\Server\$C\Harry\profile\cookies\
    etc...

2) What's the output format of your date?
You can find it by entering the following command:

    ECHO %DATE%

3) Do you want files to be deleted:
    a) on a specific date or,
    b) when files are a specific number of days old

4) Where will you be getting your date from?
0
 
LVL 1

Author Comment

by:SYPTE-IT
ID: 37741395
TwynFeyr
I can follow the structure of your code and edit to suit me, but I don't know how use it. What sort of file do I need to put the code?

paultomasi
1: structure is \\server\share\Tom\profile\cookies\
2: DD/MM/YYYY
3: b) when files are a specific number of days old
4: An admin server that any script or whatever could run on. This is ntp synched with a DC, as is the server (which is actually a VFiler) containing the files.

I'm not too worried about the to-the-second accuracy or frequency of deletion. Something that runs once a week or even once a month would be OK. I'm aware that cookies can be useful to users, but we do have some dating back to 2002!
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 11

Accepted Solution

by:
paultomasi earned 500 total points
ID: 37741724
The following batch file will delete (the specified) cookie files older than a month from when the batch file is run.

Change line 14 to the name of your 'share' location if this is not correct.
Lines 17 and 19 can be removed if you don't require a visual output of what's going on.

@echo off
for /f "tokens=1-3 delims=/" %%a in ('date /t') do (
  set day=%%a
  set /a month=%%b -1
  set year=%%c
)

if %month% lss 1 (
  set month=12
  set /a year-=1
  if %day% gtr 28 set day=28
)

pushd "\\server\share\"

for /d %%a in (*) do (
  echo Processing user: %%a
  for /f "tokens=*" %%b in ('xcopy "%%a\profile\cookies\*.*" "%temp%\" /d:%month%-%day%-%year% /c /l /y ^| find /v "File(s)"') do (
    title %%a: %%~nxb
    del /f /q "%%b"
  )
)

popd
exit /b

Open in new window

NOTE: Don't be mislead by the use of XCOPY in line 18 - it's use is purely to select files after a specific date as specified by %day%, %month% and %year% in the format m-d-y.
0
 
LVL 1

Author Comment

by:SYPTE-IT
ID: 37742795
That seems to do the trick, I've used to thin out the recent document folder too.
0
 

Expert Comment

by:TwynFeyr
ID: 37742810
Howdy,

Copy and paste into a plain text file, save and rename the file's extension to .vbs.

Double click to execute
Or, execute on the command prompt
Or, schedule and set it to run "wcript.exe [yourfilename].vbs" (or use cscript.exe if you fancy that one)

I know your probably going to anyway, but please remember to test thouroughly before you deploy.  :)

Cheers!
TwynFeyr

MSDN VBScript language reference
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37744274
Thank you
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

756 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