locked
country,year,last modified date as parameter to exclude the files RRS feed

  • Question

  • I am moving the files which are less than last modified date file to the Archive folder

    but I wanted to put parameter and not to move the files to archive

    which country wise max year and max modified date for an example

    file1_itlay_2017.xlsx last modified date is 26/6/2018 10:24 AM file1_itlay_2018.xlsx last modified date is 26/6/2018 10:24 AM

    in this case it should fetch country,year and last modified date for that partucular year

    so in output both file will be excluded

    Requirement:exlcude file via year,country and last modfied date

    i can able to achieve last modified date from below mentioned syntax

    $sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate' $destdir = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive' Get-ChildItem -File -Path $sourcedir | Sort-Object -Property LastWriteTime -Descending | Select-Object -Skip 1 | Move-Item -Destination $destdir -force





    • Edited by RUPESH1234 Tuesday, June 26, 2018 8:44 AM
    Tuesday, June 26, 2018 7:37 AM

All replies

  • any suggestions
    Tuesday, June 26, 2018 7:49 AM
  • Please do not post formatted text.  Please only post plain text for your question.  Post code using the code posting tool provided.


    \_(ツ)_/

    Tuesday, June 26, 2018 7:50 AM
  • where it is
    • Edited by RUPESH1234 Tuesday, June 26, 2018 7:58 AM
    Tuesday, June 26, 2018 7:57 AM
  • where it is

    On the edit bar: The icon with  "<>"


    \_(ツ)_/

    Tuesday, June 26, 2018 7:59 AM
  • thanks
    • Edited by RUPESH1234 Tuesday, June 26, 2018 8:06 AM
    Tuesday, June 26, 2018 8:05 AM
  • I am afraid you don't know how to post in a technical forum.  Post text of question by itself with no formatting.  Post code with code posting tool.

    Take some time to look at other questions to learn how to post a clear and readable question.


    \_(ツ)_/

    Tuesday, June 26, 2018 8:07 AM
  • Read through you own post to see why it is unreadable and hard to understand. If you seriously want to get an answer then please take the time to post correctly.


    \_(ツ)_/

    Tuesday, June 26, 2018 8:09 AM
  • removed extra words please let me know if something

    • Edited by RUPESH1234 Tuesday, June 26, 2018 8:52 AM
    Tuesday, June 26, 2018 8:45 AM
  • remove extra words<g class="gr_ gr_13 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation multiReplace" data-gr-id="13" id="13">..</g>let me know

    This post is meaningless and unreadable.


    \_(ツ)_/

    Tuesday, June 26, 2018 8:51 AM
  • done
    Tuesday, June 26, 2018 8:52 AM
  • Until you learn how to post correctly we will not be able to help you,

    Your post are not understandable and are mostly unreadable.  You need to ask a simple and clear question.


    \_(ツ)_/

    Tuesday, June 26, 2018 8:55 AM
  • what you did not understand
    • Edited by RUPESH1234 Tuesday, June 26, 2018 8:58 AM
    Tuesday, June 26, 2018 8:58 AM
  • what you did not understand

    This is not an understandable question in English.  Perhaps you would do better if you posted in a forum that supports your language or get someone you work with who has a better understanding of English to help you.

    To guess at this question I will answer: I cannot understand any part of your question.  It is poorly written and hard to read as posted.

    The following moves the newest file to the destination:

    Get-ChildItem -File -Path $sourcedir |
        Sort-Object -Property LastWriteTime -Descending |
        Select-Object -Skip 1 |
        Move-Item -Destination $destdir -force
    
    What is it not doing?  What is the error?


    \_(ツ)_/

    Tuesday, June 26, 2018 9:03 AM
  • it is power shell script in which I am excluding latest modified file and rest file moving to the archive folder

    there is no error in this just wanted to know the logic how to exclude files from the country name and year available in file name based on that max modified date for that year


    • Edited by RUPESH1234 Tuesday, June 26, 2018 9:08 AM
    Tuesday, June 26, 2018 9:07 AM
  • Still makes no sense.  What files do you want to exclude.  Just the newest file?

    The code skips the newest file.  What is the issue?


    \_(ツ)_/


    • Edited by jrv Tuesday, June 26, 2018 9:12 AM
    Tuesday, June 26, 2018 9:11 AM
  • yes any new files comes to the folder it will check the Country, Year & last modified date for

    that year in the file name

    example : file1_itlay_2017.xlsx last modified date is 26/6/2018 10:24 AM

    in this country - Italy  year- 2017 and last modified date for that year is 26/6/2018 10:24 AM

    so less than this modified dates files for this country and year, last modified date will

    be moved to archive


    Tuesday, June 26, 2018 9:25 AM
  • You will  need to parse the file names and write logic to apply your rules.  We will not do that for you.


    \_(ツ)_/

    Tuesday, June 26, 2018 9:37 AM
  • YES but what it can be the rule to do that any function or something will find year and country and last modified date
    • Edited by RUPESH1234 Tuesday, June 26, 2018 9:43 AM
    Tuesday, June 26, 2018 9:42 AM
  • YES but what it can be the rule to do that any function or something will find <g class="gr_ gr_42 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="42" id="42">year</g> and country

    You are still posting junk that is unreadable. Please look at your posts carefully.


    \_(ツ)_/

    Tuesday, June 26, 2018 9:44 AM
  • refresh it
    Tuesday, June 26, 2018 9:53 AM
  • YES but what it can be the rule to do that any function or something will find year and country and last modified date

    There is no function that can do this. You need to write the code to apply your rules.


    \_(ツ)_/

    Tuesday, June 26, 2018 9:55 AM
  • I have a requirement to exclude files based on year, country name and last modified date from that particular year and rest files from that particular year and the country moved to an archive folder

    for an example

    SS_MM_Master_finland_2018.xlsx last modified date 27/06/2018 19:00.

    SS_MM_Master_finland_2017.xlsx last modified date 27/06/2017 19:00.
    in this case, same country and year is different in the file name so that particular year- last modified date would be excluded so both the files will be excluded

    wants to know if someone can give a small example based on their experience...not necessary to be from above example or any multiple exclude rule or anything contribution would be appreciated

    I have tried

    $Files = Get-ChildItem -File C:\Setup | select Name, LastWriteTime
    You then have an export of the files like:

    Name  .......................................................                               LastWriteTime       
    ----                                 -------------       

    SS_MM_Master_Germany_2017.txt  ..........6/27/2017 4:30:09 PM

    SS_MM_Master_Germany_2017.txt  ..........6/26/2017 4:30:09 PM

    SS_MM_Master_Germany_2018.txt ...........6/27/2018 4:30:09 PM

    SS_MM_Master_Germany_2018.txt ...........6/27/2018 4:30:09 PM

    till SS_MM_Master format is same and <g class="gr_ gr_35 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="35" id="35">countryname</g>  may change based on users...expecting any dynamic query which <g class="gr_ gr_37 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="37" id="37">consider</g> country name as different string check max(modified date) based on year...any small example help <g class="gr_ gr_38 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="38" id="38">apperciated</g>
    • Merged by jrv Wednesday, June 27, 2018 8:07 PM DUPLICATE
    Wednesday, June 27, 2018 7:01 PM
  • Please do not post duplicate questions.

    No one is going to write a custom script for you.  That is not the purpose of technical forums.

    You can request a script here: Script requests


    \_(ツ)_/

    Wednesday, June 27, 2018 8:11 PM