67504

I want to maintain current date files

<h3>Question</h3>
Delete all Files in C:\temp older than Current day(s)

$Path = "E:\Testing\Order\123456"

$CurrentDate = Get-Date

Get-ChildItem $Path | Where-Object { $_.LastWriteTime -lt $CurrentDate } | Remove-Item

I am trying to run this script but it is deleting every thing. It is not maintain current date files. Is there any modification please suggesting me sir.


<h3>Answer1:</h3>

Make sure you get the file extensions right if they have any.

Get-ChildItem -Path C:\folder1\data -Include * -Exclude text.1, folder1 -Recurse | foreach { $_.Delete()}

<em>Edit to answer the comment:</em>

So you want to delete all files and folders in C:\folder1 except of files text.1 and folder.1 in data, other and alpha? It means you cannot remove these 3 folders too so they have to be excluded.

Get-ChildItem -Path C:\folder1\ -Include * -Exclude text.1, folder.1, alpha, data, other -Recurse | foreach { $_.FullName}
<h3>Answer2:</h3>

try this (and dont stay into your dir when you try) :

Get-ChildItem "C:\folder1\data\*" -Recurse | where Name -notin ('text.1', 'folder.1') | Remove-Item -Force -Recurse

来源:https://stackoverflow.com/questions/61673192/i-want-to-maintain-current-date-files

Recommend

  • Export flex chart and datagrid to excel
  • How can I make PDF tables from Perl?
  • Sort by date with jmespath
  • Single thread program to make use of multiple cores
  • Adjoining “f” and “l” characters
  • Understanding HttpServletRequest and cookies in JSF
  • got “libatk-1.0.so.0: undefined symbol” when I tried ipython --pylab in Ubuntu 13.10
  • Rails 4: Getting QRCode to display in email via action mailer
  • Removing spaces after and before commas (not between words) using command line
  • touch events not working in android phonegap webview (or even built-in browser)
  • Docker: unix “who” command doesn't work inside container
  • Python read xml with related child elements
  • How to implement JQuery confirm dialog with JSF
  • Refresh JSF component after custom javascript Ajax call
  • Use PHP to Replace HTML with HTML
  • How to get the Owner of the ContextMenu (from Silverlight 4 toolkit)?
  • How to process remote XML files with XSLT
  • Query regarding com.jcraft.jsch.JSchException: UnknownHostKey: x.y.com. DSA key fingerprint is “ac:e
  • 'Edit' function for forum posts and such
  • Add font awesome icon to custom add to cart button in Woocommerce 3
  • how to read to huge file into buffer
  • Create an average of multiple excel chart without the data source
  • r - input value by user to dataframe via shiny
  • JQuery: Infinite input select
  • how to run ejabberd with Erlang on Heroku?
  • How to use Streams api peek() function and make it work?
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?
  • How to handle div that is created dynamically in a table
  • Google App Engine backend servlet not responding
  • Android Library Projects on Windows and Mac
  • How to use FirstOrDefault inside Include
  • PHP Permalinks.. how to change?
  • Running R's aov() mixed effects model from Python using rpy2
  • ReferenceError: TextEncoder is not defined