![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | ftpusers I want create a script that after x amount of days any files under ftp share will be deleted... please help I am new to powershell thanks Frank |
My System Specs![]() |
| | #2 (permalink) |
| | RE: ftpusers Try something like this ## This script will remove files older than a given date $folder = "c:\test" # folder to test $NumDays = 30 # maximum age of file in days to allow $CurDate = get-date # current date $TestDate = $Curdate.AddDays(-$NumDays) # set TestDate # ceate log file $strData = "Files deleted from: " + $folder + " on " + $CurDate $strData | out-file DeletedFiles.log # get the files in the folder and determine if older than $NumDays get-childitem $folder | foreach { If ($_.GetType().Name -eq "FileInfo") { If ($_.LastWriteTime -lt $TestDate) { $strData = "File to delete: " + $_.Name + " " + $_.LastWriteTime $strData | out-file -Append DeletedFiles.log $_.Delete() } } } Change the folder & number of days to suit your needs -- 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 "frank" wrote: > I want create a script that after x amount of days any files under ftp share > will be deleted... > > please help I am new to powershell > > > thanks > > Frank |
My System Specs![]() |
| | #3 (permalink) |
| | RE: ftpusers I forgot to tell you that I want to delete folders from a sub-directory i.e \abfolder \bbfolder so if \ftp\abfolder or if bbfolder and so on had over 180 days it will delte the files Thanks "RichS" wrote: > Try something like this > > ## This script will remove files older than a given date > > $folder = "c:\test" # folder to test > $NumDays = 30 # maximum age of file in days to allow > > $CurDate = get-date # current date > $TestDate = $Curdate.AddDays(-$NumDays) # set TestDate > > # ceate log file > $strData = "Files deleted from: " + $folder + " on " + $CurDate > $strData | out-file DeletedFiles.log > > # get the files in the folder and determine if older than $NumDays > > get-childitem $folder | foreach { > > If ($_.GetType().Name -eq "FileInfo") > { > > If ($_.LastWriteTime -lt $TestDate) > { > $strData = "File to delete: " + $_.Name + " " + $_.LastWriteTime > $strData | out-file -Append DeletedFiles.log > $_.Delete() > } > > } > > > > } > > Change the folder & number of days to suit your needs > > -- > 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 > > > "frank" wrote: > > > I want create a script that after x amount of days any files under ftp share > > will be deleted... > > > > please help I am new to powershell > > > > > > thanks > > > > Frank |
My System Specs![]() |
| | #4 (permalink) |
| | Re: ftpusers On Feb 27, 3:53 pm, RichS <R...@discussions.microsoft.com> wrote: > Try something like this > > ## This script will remove files older than a given date > > $folder = "c:\test" # folder to test > $NumDays = 30 # maximum age of file in days to allow > > $CurDate = get-date # current date > $TestDate = $Curdate.AddDays(-$NumDays) # set TestDate > > # ceate log file > $strData = "Files deleted from: " + $folder + " on " + $CurDate > $strData | out-file DeletedFiles.log > > # get the files in the folder and determine if older than $NumDays > > get-childitem $folder | foreach { > > If ($_.GetType().Name -eq "FileInfo") > { > > If ($_.LastWriteTime -lt $TestDate) > { > $strData = "File to delete: " + $_.Name + " " + $_.LastWriteTime > $strData | out-file -Append DeletedFiles.log > $_.Delete() > } > > } > > } > > Change the folder & number of days to suit your needs > > -- > 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 > > "frank" wrote: > > I want create a script that after x amount of days any files under ftp share > > will be deleted... > > > please help I am new to powershell > > > thanks > > > Frank Hi Frank, If you use the -recurse flag on the Get-ChildItem cmdlet then it will walk down the folder tree in the manenr you want. so, replace "Get-ChildItem $folder" to "Get-ChildItem -recurse $folder" Matt |
My System Specs![]() |
![]() |
| Thread Tools | |
| |