Welcome Forums General PowerShell Q&A compress & move files, filtering by year & month YYYYMMDD in filename.

Viewing 4 reply threads
  • Author
    Posts
    • #173491
      Participant
      Topics: 3
      Replies: 9
      Points: 59
      Rank: Member

      Hi Guys

      You have previously help me with some code that I needed, without me having a wast knowledge about PowerShell.
      So I am hoping you can do it again. 🙂

      I am looking to make a script that can help me clean up folders containing files that are generated daily going back to 2016, there are now millions of files pr. folder. And therefore I can either make a simple script that can find files containing part of the file name and then compressing those files and move them.

      But if I wanted to compress and move files for each month going back to 2016, and this needs to be done on a lot of folders, each month.  I would normally do this by manually typing in (finding all files *_201601*.csv) and next (find all files *_201602*.csv) and so on for all month all years going back.

      I was hoping to automate this process 🙂

      • Find a year & month in a filename -> in this case 20180802 ( File -> 0016000449_00168737_valuereport_20180827104607_2105.csv)
      • Use 201808 to find all files containing *201808* in a specific folder.
      • Compress these files and move them, thereafter delete them.

      Simple enough, if I just want to do this, I could manually change the date for each month going back to 2016.

      But I know how to do that. So what I need is for Powershell to:

      • Do the above action, by year&month automatically. Powershell should find all 201808 files, compress/move, and move on to 201809. repeat for 201810 and then on and on until the folder almost is empty.
      • Reson, why I write almost, is that I only need to this action for all files that are older than 90 days (3 months) so something like <=today()-90

      I know I am asking a lot, but maybe some links for other similar questions, or solutions would also be helpful.
      I just haven´t been able to find a similar question for this specific need on Google.

    • #173494
      Participant
      Topics: 2
      Replies: 1761
      Points: 3,655
      Helping Hand
      Rank: Community Hero

      We’re used to be better when we get something to tweak. What do you have so far? Please show you code. Powershell.org is not a free code writing service – you know that, right? We expect you to do your own research before and at least try to solve your problem by yourself.

    • #173497
      Participant
      Topics: 3
      Replies: 9
      Points: 59
      Rank: Member

      Hi Olaf

       

      That is fair enough, did not know how much I could ask you guys for help.
      Hang on and I will get back with something that makes more sense, and with research, time put into it 🙂

    • #174436
      Participant
      Topics: 0
      Replies: 115
      Points: 433
      Helping Hand
      Rank: Contributor

      Hello Danky,

      Just following up to determine if you have figured out the solution or you still need assistance.

    • #174523
      Participant
      Topics: 3
      Replies: 9
      Points: 59
      Rank: Member

      Hi Jason

      Thank you for the followup.
      I found another solution and did not know how to remove or close this ticket.

Viewing 4 reply threads
  • The topic ‘compress & move files, filtering by year & month YYYYMMDD in filename.’ is closed to new replies.