[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Search multiple folders in windows

Posted on 2012-03-19
7
Medium Priority
?
310 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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Accepted Solution

by:
paultomasi earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
Unable to change the program that handles the scan event from a network attached Canon/Brother printer/scanner. This means you'll always have to choose which program handles this action, e.g. ControlCenter4 (in the case of a Brother).
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

873 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