问题 File management

  • Wednesday, May 09, 2012 9:03 PM
     
     
    Hi,
    i would like to write a powershell script, that make the following:
    - search in a rootdirectory for all files
    - if in rootdirectory exists the file with last write time yyyy.MM.01, write to host and search for yyyy.MM.17
    - if a file not exists with last write time yyyy.MM.01, search for yyyy.MM.02, if 02 not exists search for 03.....
    - if a file not exists with last write time yyyy.MM.17, search for 18.... 
    I have written a script for this, but doesn't work:
    foreach($year in $years){
        foreach($month in $months){ 
        $day1=1 
        $day2=31
                 while($day1 -lt $day2){
                 Get-ChildItem -Path $routepath | Where-Object { $_.Mode -notmatch 'd' } | ForEach-Object {
                         if($year -eq $_.lastwritetime.year -and $month -eq $_.lastwritetime.month -and $day1 -eq $_.lastwritetime.day){
                              $_
                              $day1 = 17
                         }
                         else{
                         $day1 += 1
                         }
                  }
                  }
         }
    }
    can you help me?
    Thanks,
    gonan86

All Replies

  • Wednesday, May 09, 2012 9:18 PM
     
     

    Your description of how the program should work doesn't make sense.  That is not proper psuedo-code.  There are too many questions unanswered.

    Please think carefully about what you want, and be sure to cover all scenarios.

    Once you have the idea fully thought out, you may be able to write some sensible code.  The code you posted makes no sense either.


    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

  • Friday, May 11, 2012 6:37 AM
    Moderator
     
     

    Hi,

    I am agree with Bigteddy, it is hard for us to know what do you want to achieve, and what do you want to get.

    Please tell us more about your goal.

    Regards,

    Yan Li


    Yan Li

    TechNet Community Support