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
Solved

Search multiple folders in windows

Posted on 2012-03-19
7
300 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

839 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