Windows Vista Forums

directory and file date

  1. #1


    Brandon Shell Guest

    Re: directory and file date

    Try this. I assumed you meant last changed.
    get-childitem e: -recurse | where{$_.LastWriteTime -lt
    (([datetime]::now).Addmonths(-3))}


    "frank" <frank@discussions.microsoft.com> wrote in message
    news:48C96B5F-970B-428F-883C-02D7DAFB8178@microsoft.com...
    >I was wondering if any has a script that will check an e: drive directory
    >and
    > subdirctory but only listthe directory and files that are older then 3
    > months
    >
    >
    > thanks
    >
    >
    >
    > frank



      My System SpecsSystem Spec

  2.   


  3. #2


    frank Guest

    directory and file date

    I was wondering if any has a script that will check an e: drive directory and
    subdirctory but only listthe directory and files that are older then 3 months


    thanks



    frank

      My System SpecsSystem Spec

  4. #3


    ebgreen Guest

    RE: directory and file date

    Here is a quick one-liner that will hopefully point you in the right
    direction. It should list all the files and folders that were accessed more
    than 45 days ago:

    ls | ?{((get-date).Subtract($_.LastWriteTime).Days -gt 45)}

    "frank" wrote:

    > I was wondering if any has a script that will check an e: drive directory and
    > subdirctory but only listthe directory and files that are older then 3 months
    >
    >
    > thanks
    >
    >
    >
    > frank


      My System SpecsSystem Spec

  5. #4


    Brandon Shell Guest

    Re: directory and file date

    Sup Ebgreen... just some helpful hints.

    - When posting stuff for other people I try to avoid alias (I know, I
    know... it is super hard)

    - Not sure you know, but system.datetime has a few methods you can add
    negative numbers to that are quite useful
    AddDays
    AddHours
    AddMilliseconds
    AddMinutes
    AddMonths
    AddSeconds
    AddTicks
    AddYears

    - For access time I would use .LastAccessTime instead LastWriteTime

    "ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
    news:F6E82F07-5945-4770-85E6-2792466373C3@microsoft.com...
    > Here is a quick one-liner that will hopefully point you in the right
    > direction. It should list all the files and folders that were accessed
    > more
    > than 45 days ago:
    >
    > ls | ?{((get-date).Subtract($_.LastWriteTime).Days -gt 45)}
    >
    > "frank" wrote:
    >
    >> I was wondering if any has a script that will check an e: drive directory
    >> and
    >> subdirctory but only listthe directory and files that are older then 3
    >> months
    >>
    >>
    >> thanks
    >>
    >>
    >>
    >> frank



      My System SpecsSystem Spec

  6. #5


    ebgreen Guest

    Re: directory and file date

    All very valid points. I have mixed feelings regarding aliases. On the one
    hand I generally avoid then in script files. I think they would make
    maintenance difficult since there is no guarantee that they will always
    exist. At the command line I use them extensively. As for posting in threads,
    I think that while it could be confusing to someone who doesn't know them,
    how else will they learn about them? I didn't know ? = Where-Object until I
    saw it in a blog post one time. Generally I do avoid them in posts. What I
    will do is work out the answer at the command line using aliases then post
    the line without the alias. (Hey, that would be a nice function. You hand it
    a string and it gives the string back with all the aliases replaced by the
    actual command.) In this case I was just being lazy and did a copy and paste.
    Also, not to be pedantic, but you used an alias as well (where).

    As for .LastAccessTime vs. .LastWriteTime I suppose it would depend on the
    original poster's need. When I look at archive scripts I usually don't care
    how long it has been since someone looked at the file, I just care about the
    last time that someone made a change to the file. Although the other view is
    just as (and perhaps more) valid.

    So here is my suggestion with the proposed changes:

    get-childitem | where-object{((get-date).Subtract($_.LastAccessTime).Days
    -gt 45)}


    "Brandon Shell" wrote:

    > Sup Ebgreen... just some helpful hints.
    >
    > - When posting stuff for other people I try to avoid alias (I know, I
    > know... it is super hard)
    >
    > - Not sure you know, but system.datetime has a few methods you can add
    > negative numbers to that are quite useful
    > AddDays
    > AddHours
    > AddMilliseconds
    > AddMinutes
    > AddMonths
    > AddSeconds
    > AddTicks
    > AddYears
    >
    > - For access time I would use .LastAccessTime instead LastWriteTime
    >
    > "ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
    > news:F6E82F07-5945-4770-85E6-2792466373C3@microsoft.com...
    > > Here is a quick one-liner that will hopefully point you in the right
    > > direction. It should list all the files and folders that were accessed
    > > more
    > > than 45 days ago:
    > >
    > > ls | ?{((get-date).Subtract($_.LastWriteTime).Days -gt 45)}
    > >
    > > "frank" wrote:
    > >
    > >> I was wondering if any has a script that will check an e: drive directory
    > >> and
    > >> subdirctory but only listthe directory and files that are older then 3
    > >> months
    > >>
    > >>
    > >> thanks
    > >>
    > >>
    > >>
    > >> frank

    >
    >


      My System SpecsSystem Spec

  7. #6


    Brandon Shell Guest

    Re: directory and file date

    Are you writting this one

    "Hey, that would be a nice function. You hand it
    a string and it gives the string back with all the aliases replaced by the
    actual command.) In this case I was just being lazy and did a copy and
    paste.
    Also, not to be pedantic, but you used an alias as well (where). "


    "ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
    news:2A87B130-D20D-4A85-A35A-118BE06EF235@microsoft.com...
    > All very valid points. I have mixed feelings regarding aliases. On the one
    > hand I generally avoid then in script files. I think they would make
    > maintenance difficult since there is no guarantee that they will always
    > exist. At the command line I use them extensively. As for posting in
    > threads,
    > I think that while it could be confusing to someone who doesn't know them,
    > how else will they learn about them? I didn't know ? = Where-Object until
    > I
    > saw it in a blog post one time. Generally I do avoid them in posts. What I
    > will do is work out the answer at the command line using aliases then post
    > the line without the alias. (Hey, that would be a nice function. You hand
    > it
    > a string and it gives the string back with all the aliases replaced by the
    > actual command.) In this case I was just being lazy and did a copy and
    > paste.
    > Also, not to be pedantic, but you used an alias as well (where).
    >
    > As for .LastAccessTime vs. .LastWriteTime I suppose it would depend on the
    > original poster's need. When I look at archive scripts I usually don't
    > care
    > how long it has been since someone looked at the file, I just care about
    > the
    > last time that someone made a change to the file. Although the other view
    > is
    > just as (and perhaps more) valid.
    >
    > So here is my suggestion with the proposed changes:
    >
    > get-childitem | where-object{((get-date).Subtract($_.LastAccessTime).Days
    > -gt 45)}
    >
    >
    > "Brandon Shell" wrote:
    >
    >> Sup Ebgreen... just some helpful hints.
    >>
    >> - When posting stuff for other people I try to avoid alias (I know, I
    >> know... it is super hard)
    >>
    >> - Not sure you know, but system.datetime has a few methods you can add
    >> negative numbers to that are quite useful
    >> AddDays
    >> AddHours
    >> AddMilliseconds
    >> AddMinutes
    >> AddMonths
    >> AddSeconds
    >> AddTicks
    >> AddYears
    >>
    >> - For access time I would use .LastAccessTime instead LastWriteTime
    >>
    >> "ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
    >> news:F6E82F07-5945-4770-85E6-2792466373C3@microsoft.com...
    >> > Here is a quick one-liner that will hopefully point you in the right
    >> > direction. It should list all the files and folders that were accessed
    >> > more
    >> > than 45 days ago:
    >> >
    >> > ls | ?{((get-date).Subtract($_.LastWriteTime).Days -gt 45)}
    >> >
    >> > "frank" wrote:
    >> >
    >> >> I was wondering if any has a script that will check an e: drive
    >> >> directory
    >> >> and
    >> >> subdirctory but only listthe directory and files that are older then 3
    >> >> months
    >> >>
    >> >>
    >> >> thanks
    >> >>
    >> >>
    >> >>
    >> >> frank

    >>
    >>



      My System SpecsSystem Spec

  8. #7


    Shay Levi Guest

    Re: directory and file date

    >> Hey, that would be a nice function...
    I think it exists in PrimalScript 2007

    As for writing posts with aliases, you can always add a comment like

    # ? = where-object
    # % = foreach-object
    dir . | % {some code}


    Shay
    http://scriptolog.blogspot.com



    > All very valid points. I have mixed feelings regarding aliases. On the
    > one hand I generally avoid then in script files. I think they would
    > make maintenance difficult since there is no guarantee that they will
    > always exist. At the command line I use them extensively. As for
    > posting in threads, I think that while it could be confusing to
    > someone who doesn't know them, how else will they learn about them? I
    > didn't know ? = Where-Object until I saw it in a blog post one time.
    > Generally I do avoid them in posts. What I will do is work out the
    > answer at the command line using aliases then post the line without
    > the alias. (Hey, that would be a nice function. You hand it a string
    > and it gives the string back with all the aliases replaced by the
    > actual command.) In this case I was just being lazy and did a copy and
    > paste. Also, not to be pedantic, but you used an alias as well
    > (where).
    >
    > As for .LastAccessTime vs. .LastWriteTime I suppose it would depend on
    > the original poster's need. When I look at archive scripts I usually
    > don't care how long it has been since someone looked at the file, I
    > just care about the last time that someone made a change to the file.
    > Although the other view is just as (and perhaps more) valid.
    >
    > So here is my suggestion with the proposed changes:
    >
    > get-childitem |
    > where-object{((get-date).Subtract($_.LastAccessTime).Days -gt 45)}
    >
    > "Brandon Shell" wrote:
    >
    >> Sup Ebgreen... just some helpful hints.
    >>
    >> - When posting stuff for other people I try to avoid alias (I know, I
    >> know... it is super hard)
    >>
    >> - Not sure you know, but system.datetime has a few methods you can
    >> add
    >> negative numbers to that are quite useful
    >> AddDays
    >> AddHours
    >> AddMilliseconds
    >> AddMinutes
    >> AddMonths
    >> AddSeconds
    >> AddTicks
    >> AddYears
    >> - For access time I would use .LastAccessTime instead LastWriteTime
    >>
    >> "ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
    >> news:F6E82F07-5945-4770-85E6-2792466373C3@microsoft.com...
    >>
    >>> Here is a quick one-liner that will hopefully point you in the right
    >>> direction. It should list all the files and folders that were
    >>> accessed
    >>> more
    >>> than 45 days ago:
    >>> ls | ?{((get-date).Subtract($_.LastWriteTime).Days -gt 45)}
    >>>
    >>> "frank" wrote:
    >>>
    >>>> I was wondering if any has a script that will check an e: drive
    >>>> directory
    >>>> and
    >>>> subdirctory but only listthe directory and files that are older
    >>>> then 3
    >>>> months
    >>>> thanks
    >>>>
    >>>> frank
    >>>>




      My System SpecsSystem Spec

  9. #8


    ebgreen Guest

    Re: directory and file date

    I've given it some thought and for the time being, no. It would actually
    have to be a fairly complex recursive descent parser and I don't have that
    much free time.

    "Shay Levi" wrote:

    > >> Hey, that would be a nice function...

    > I think it exists in PrimalScript 2007
    >
    > As for writing posts with aliases, you can always add a comment like
    >
    > # ? = where-object
    > # % = foreach-object
    > dir . | % {some code}
    >
    >
    > Shay
    > http://scriptolog.blogspot.com
    >
    >
    >
    > > All very valid points. I have mixed feelings regarding aliases. On the
    > > one hand I generally avoid then in script files. I think they would
    > > make maintenance difficult since there is no guarantee that they will
    > > always exist. At the command line I use them extensively. As for
    > > posting in threads, I think that while it could be confusing to
    > > someone who doesn't know them, how else will they learn about them? I
    > > didn't know ? = Where-Object until I saw it in a blog post one time.
    > > Generally I do avoid them in posts. What I will do is work out the
    > > answer at the command line using aliases then post the line without
    > > the alias. (Hey, that would be a nice function. You hand it a string
    > > and it gives the string back with all the aliases replaced by the
    > > actual command.) In this case I was just being lazy and did a copy and
    > > paste. Also, not to be pedantic, but you used an alias as well
    > > (where).
    > >
    > > As for .LastAccessTime vs. .LastWriteTime I suppose it would depend on
    > > the original poster's need. When I look at archive scripts I usually
    > > don't care how long it has been since someone looked at the file, I
    > > just care about the last time that someone made a change to the file.
    > > Although the other view is just as (and perhaps more) valid.
    > >
    > > So here is my suggestion with the proposed changes:
    > >
    > > get-childitem |
    > > where-object{((get-date).Subtract($_.LastAccessTime).Days -gt 45)}
    > >
    > > "Brandon Shell" wrote:
    > >
    > >> Sup Ebgreen... just some helpful hints.
    > >>
    > >> - When posting stuff for other people I try to avoid alias (I know, I
    > >> know... it is super hard)
    > >>
    > >> - Not sure you know, but system.datetime has a few methods you can
    > >> add
    > >> negative numbers to that are quite useful
    > >> AddDays
    > >> AddHours
    > >> AddMilliseconds
    > >> AddMinutes
    > >> AddMonths
    > >> AddSeconds
    > >> AddTicks
    > >> AddYears
    > >> - For access time I would use .LastAccessTime instead LastWriteTime
    > >>
    > >> "ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
    > >> news:F6E82F07-5945-4770-85E6-2792466373C3@microsoft.com...
    > >>
    > >>> Here is a quick one-liner that will hopefully point you in the right
    > >>> direction. It should list all the files and folders that were
    > >>> accessed
    > >>> more
    > >>> than 45 days ago:
    > >>> ls | ?{((get-date).Subtract($_.LastWriteTime).Days -gt 45)}
    > >>>
    > >>> "frank" wrote:
    > >>>
    > >>>> I was wondering if any has a script that will check an e: drive
    > >>>> directory
    > >>>> and
    > >>>> subdirctory but only listthe directory and files that are older
    > >>>> then 3
    > >>>> months
    > >>>> thanks
    > >>>>
    > >>>> frank
    > >>>>

    >
    >
    >


      My System SpecsSystem Spec

  10. #9


    ebgreen Guest

    Re: directory and file date

    Ooops...replied to the wrong post. My post immediately above should be here.

    "Brandon Shell" wrote:

    > Are you writting this one
    >
    > "Hey, that would be a nice function. You hand it
    > a string and it gives the string back with all the aliases replaced by the
    > actual command.) In this case I was just being lazy and did a copy and
    > paste.
    > Also, not to be pedantic, but you used an alias as well (where). "
    >
    >
    > "ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
    > news:2A87B130-D20D-4A85-A35A-118BE06EF235@microsoft.com...
    > > All very valid points. I have mixed feelings regarding aliases. On the one
    > > hand I generally avoid then in script files. I think they would make
    > > maintenance difficult since there is no guarantee that they will always
    > > exist. At the command line I use them extensively. As for posting in
    > > threads,
    > > I think that while it could be confusing to someone who doesn't know them,
    > > how else will they learn about them? I didn't know ? = Where-Object until
    > > I
    > > saw it in a blog post one time. Generally I do avoid them in posts. What I
    > > will do is work out the answer at the command line using aliases then post
    > > the line without the alias. (Hey, that would be a nice function. You hand
    > > it
    > > a string and it gives the string back with all the aliases replaced by the
    > > actual command.) In this case I was just being lazy and did a copy and
    > > paste.
    > > Also, not to be pedantic, but you used an alias as well (where).
    > >
    > > As for .LastAccessTime vs. .LastWriteTime I suppose it would depend on the
    > > original poster's need. When I look at archive scripts I usually don't
    > > care
    > > how long it has been since someone looked at the file, I just care about
    > > the
    > > last time that someone made a change to the file. Although the other view
    > > is
    > > just as (and perhaps more) valid.
    > >
    > > So here is my suggestion with the proposed changes:
    > >
    > > get-childitem | where-object{((get-date).Subtract($_.LastAccessTime).Days
    > > -gt 45)}
    > >
    > >
    > > "Brandon Shell" wrote:
    > >
    > >> Sup Ebgreen... just some helpful hints.
    > >>
    > >> - When posting stuff for other people I try to avoid alias (I know, I
    > >> know... it is super hard)
    > >>
    > >> - Not sure you know, but system.datetime has a few methods you can add
    > >> negative numbers to that are quite useful
    > >> AddDays
    > >> AddHours
    > >> AddMilliseconds
    > >> AddMinutes
    > >> AddMonths
    > >> AddSeconds
    > >> AddTicks
    > >> AddYears
    > >>
    > >> - For access time I would use .LastAccessTime instead LastWriteTime
    > >>
    > >> "ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
    > >> news:F6E82F07-5945-4770-85E6-2792466373C3@microsoft.com...
    > >> > Here is a quick one-liner that will hopefully point you in the right
    > >> > direction. It should list all the files and folders that were accessed
    > >> > more
    > >> > than 45 days ago:
    > >> >
    > >> > ls | ?{((get-date).Subtract($_.LastWriteTime).Days -gt 45)}
    > >> >
    > >> > "frank" wrote:
    > >> >
    > >> >> I was wondering if any has a script that will check an e: drive
    > >> >> directory
    > >> >> and
    > >> >> subdirctory but only listthe directory and files that are older then 3
    > >> >> months
    > >> >>
    > >> >>
    > >> >> thanks
    > >> >>
    > >> >>
    > >> >>
    > >> >> frank
    > >>
    > >>

    >
    >


      My System SpecsSystem Spec

  11. #10


    RichS Guest

    Re: directory and file date

    I did started something like that a few weeks back. See

    http://richardsiddaway.spaces.live.c...3E96!543.entry

    --
    Richard Siddaway
    Please note that all scripts are supplied "as is" and with no warranty
    Blog: http://richardsiddaway.spaces.live.com/
    PowerShell User Group: http://www.get-psuguk.org.uk


    "ebgreen" wrote:

    > All very valid points. I have mixed feelings regarding aliases. On the one
    > hand I generally avoid then in script files. I think they would make
    > maintenance difficult since there is no guarantee that they will always
    > exist. At the command line I use them extensively. As for posting in threads,
    > I think that while it could be confusing to someone who doesn't know them,
    > how else will they learn about them? I didn't know ? = Where-Object until I
    > saw it in a blog post one time. Generally I do avoid them in posts. What I
    > will do is work out the answer at the command line using aliases then post
    > the line without the alias. (Hey, that would be a nice function. You hand it
    > a string and it gives the string back with all the aliases replaced by the
    > actual command.) In this case I was just being lazy and did a copy and paste.
    > Also, not to be pedantic, but you used an alias as well (where).
    >
    > As for .LastAccessTime vs. .LastWriteTime I suppose it would depend on the
    > original poster's need. When I look at archive scripts I usually don't care
    > how long it has been since someone looked at the file, I just care about the
    > last time that someone made a change to the file. Although the other view is
    > just as (and perhaps more) valid.
    >
    > So here is my suggestion with the proposed changes:
    >
    > get-childitem | where-object{((get-date).Subtract($_.LastAccessTime).Days
    > -gt 45)}
    >
    >
    > "Brandon Shell" wrote:
    >
    > > Sup Ebgreen... just some helpful hints.
    > >
    > > - When posting stuff for other people I try to avoid alias (I know, I
    > > know... it is super hard)
    > >
    > > - Not sure you know, but system.datetime has a few methods you can add
    > > negative numbers to that are quite useful
    > > AddDays
    > > AddHours
    > > AddMilliseconds
    > > AddMinutes
    > > AddMonths
    > > AddSeconds
    > > AddTicks
    > > AddYears
    > >
    > > - For access time I would use .LastAccessTime instead LastWriteTime
    > >
    > > "ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
    > > news:F6E82F07-5945-4770-85E6-2792466373C3@microsoft.com...
    > > > Here is a quick one-liner that will hopefully point you in the right
    > > > direction. It should list all the files and folders that were accessed
    > > > more
    > > > than 45 days ago:
    > > >
    > > > ls | ?{((get-date).Subtract($_.LastWriteTime).Days -gt 45)}
    > > >
    > > > "frank" wrote:
    > > >
    > > >> I was wondering if any has a script that will check an e: drive directory
    > > >> and
    > > >> subdirctory but only listthe directory and files that are older then 3
    > > >> months
    > > >>
    > > >>
    > > >> thanks
    > > >>
    > > >>
    > > >>
    > > >> frank

    > >
    > >


      My System SpecsSystem Spec

Page 1 of 2 12 LastLast

directory and file date
Similar Threads
Thread Forum
Create Directory with date time stamp PowerShell
Copy file from one directory to a new directory, using excelspreadsheet as reference for items to be copied VB Script
Directory creation with a today's date PowerShell
Setting up a directory and moving a file into that directory from Vista General
Setting up a directory and moving a file into that directory from Vista General