?
Solved

Search multiple folders in windows

Posted on 2012-03-19
7
Medium Priority
?
305 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
The Ideal Solution for Multi-Display Applications

Check out ATEN’s VS1912 12-Port DP Video Wall Media Player at InfoComm 2017. Kerri describes how easy it is to design creative video walls in asymmetric layouts and schedule detailed playlists ahead of time with its advanced scheduling feature.

 
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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Suggested Courses

801 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