PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms..win.server.scripting > Deleting Files and folders
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Deleting Files and folders

Réponse
 
LinkBack Outils de la discussion
Vieux 20/11/2007, 14h50   #1
po_boy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Deleting Files and folders

I have some files and folders under C:\LogFiles. This folder has many
subfolders and files. I need to find an easy way to delete the files or
folders(subfolder) that are older than X days. Most scripts only do a folder
and files but not a group and since I am not that good with scripts it is not
working well for my needs. Please assist.
  Réponse avec citation
Vieux 20/11/2007, 20h45   #2
Jeffery Hicks [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Deleting Files and folders

See if this s get you in the right direction.

On Error Resume NextstrFolder="f:\data"
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFolder=objFSO.GetFolder(strFolder)
Set colFiles=objFolder.Files
For Each file In colFiles
If Int(DateDiff("d",file.DateLastModified,Now)) >= 60 Then
WScript.Echo "Deleting " & file & " (" &_
file.DateLastModified & ")"
objFSO.DeleteFile file,True
If Err.Number<>0 Then
WScript.Echo "**Failed to delete " & file & ". Error# " &_
Err.Number & " " & Err.Description & "**"
End If
End If
Next
'end of script

This script finds all files in F:\Data that are > 60 days old based on date
last modified and deletes them. You could take this code and create a
function so you could recurse through subfolders.

--
Jeffery Hicks
Microsoft PowerShell MVP
http://www.scriptinganswers.com
http://www.powershellcommunity.org

Now Available: WSH and VBScript Core: TFM
Coming Soon: Windows PowerShell: TFM 2nd Ed.

"po_boy" <poboy@discussions.microsoft.com> wrote in message
newsDFA0136-97B9-4D00-B847-0614060EF44F@microsoft.com...
>I have some files and folders under C:\LogFiles. This folder has many
> subfolders and files. I need to find an easy way to delete the files or
> folders(subfolder) that are older than X days. Most scripts only do a
> folder
> and files but not a group and since I am not that good with scripts it is
> not
> working well for my needs. Please assist.


  Réponse avec citation
Vieux 20/11/2007, 21h40   #3
po_boy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Deleting Files and folders

Thanks Jeffery, but that is the problem. I am not versed enought in functions
to make it delete the sub-folders and or files.

"Jeffery Hicks [MVP]" wrote:

> See if this s get you in the right direction.
>
> On Error Resume NextstrFolder="f:\data"
> Set objFSO=CreateObject("Scripting.FileSystemObject")
> Set objFolder=objFSO.GetFolder(strFolder)
> Set colFiles=objFolder.Files
> For Each file In colFiles
> If Int(DateDiff("d",file.DateLastModified,Now)) >= 60 Then
> WScript.Echo "Deleting " & file & " (" &_
> file.DateLastModified & ")"
> objFSO.DeleteFile file,True
> If Err.Number<>0 Then
> WScript.Echo "**Failed to delete " & file & ". Error# " &_
> Err.Number & " " & Err.Description & "**"
> End If
> End If
> Next
> 'end of script
>
> This script finds all files in F:\Data that are > 60 days old based on date
> last modified and deletes them. You could take this code and create a
> function so you could recurse through subfolders.
>
> --
> Jeffery Hicks
> Microsoft PowerShell MVP
> http://www.scriptinganswers.com
> http://www.powershellcommunity.org
>
> Now Available: WSH and VBScript Core: TFM
> Coming Soon: Windows PowerShell: TFM 2nd Ed.
>
> "po_boy" <poboy@discussions.microsoft.com> wrote in message
> newsDFA0136-97B9-4D00-B847-0614060EF44F@microsoft.com...
> >I have some files and folders under C:\LogFiles. This folder has many
> > subfolders and files. I need to find an easy way to delete the files or
> > folders(subfolder) that are older than X days. Most scripts only do a
> > folder
> > and files but not a group and since I am not that good with scripts it is
> > not
> > working well for my needs. Please assist.

>

  Réponse avec citation
Vieux 20/11/2007, 22h28   #4
Jeffery Hicks [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Deleting Files and folders

I don't have time to write you a complete script. Basically you need to do
something like this:

On Error Resume Next
strFolder="f:\data"
Call DeleteOldFiles(strFolder)

wscript.quit 'end main script

Sub DeleteOldFiles(strFolder)
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFolder=objFSO.GetFolder(strFolder)
Set colFiles=objFolder.Files
For Each file In colFiles
If Int(DateDiff("d",file.DateLastModified,Now)) >= 60 Then
WScript.Echo "Deleting " & file & " (" &_
file.DateLastModified & ")"
objFSO.DeleteFile file,True
If Err.Number<>0 Then
WScript.Echo "**Failed to delete " & file & ". Error# " &_
Err.Number & " " & Err.Description & "**"
End If
End If
Next
Set colSubs=-objFolder.SubFolders
For Each subFldr In colSubs
Call DeleteOldFiles(subFldr)
next
end sub
'end of script

I strongly suggest you pick up one or two books on scripting. I always
recommend VBScript, WMI and ADSI Unleashed by Don Jones as a good tutorial.
My WSH and VBScript Core: TFM is a complete language reference with
real-world and practical examples of every object, function, method,
property and statement you are likely to need in VBScript.

--
Jeffery Hicks
Microsoft PowerShell MVP
http://www.scriptinganswers.com
http://www.powershellcommunity.org

Now Available: WSH and VBScript Core: TFM
Coming Soon: Windows PowerShell: TFM 2nd Ed.
"po_boy" <poboy@discussions.microsoft.com> wrote in message
news:0C9E58D5-98D5-4535-B406-B5DD7EAF1998@microsoft.com...
> Thanks Jeffery, but that is the problem. I am not versed enought in
> functions
> to make it delete the sub-folders and or files.
>
> "Jeffery Hicks [MVP]" wrote:
>
>> See if this s get you in the right direction.
>>
>> On Error Resume Next

strFolder="f:\data"
>> Set objFSO=CreateObject("Scripting.FileSystemObject")
>> Set objFolder=objFSO.GetFolder(strFolder)
>> Set colFiles=objFolder.Files
>> For Each file In colFiles
>> If Int(DateDiff("d",file.DateLastModified,Now)) >= 60 Then
>> WScript.Echo "Deleting " & file & " (" &_
>> file.DateLastModified & ")"
>> objFSO.DeleteFile file,True
>> If Err.Number<>0 Then
>> WScript.Echo "**Failed to delete " & file & ". Error# " &_
>> Err.Number & " " & Err.Description & "**"
>> End If
>> End If
>> Next
>> 'end of script
>>
>> This script finds all files in F:\Data that are > 60 days old based on
>> date
>> last modified and deletes them. You could take this code and create a
>> function so you could recurse through subfolders.
>>
>> --
>> Jeffery Hicks
>> Microsoft PowerShell MVP
>> http://www.scriptinganswers.com
>> http://www.powershellcommunity.org
>>
>> Now Available: WSH and VBScript Core: TFM
>> Coming Soon: Windows PowerShell: TFM 2nd Ed.
>>
>> "po_boy" <poboy@discussions.microsoft.com> wrote in message
>> newsDFA0136-97B9-4D00-B847-0614060EF44F@microsoft.com...
>> >I have some files and folders under C:\LogFiles. This folder has many
>> > subfolders and files. I need to find an easy way to delete the files or
>> > folders(subfolder) that are older than X days. Most scripts only do a
>> > folder
>> > and files but not a group and since I am not that good with scripts it
>> > is
>> > not
>> > working well for my needs. Please assist.

>>


  Réponse avec citation
Vieux 21/11/2007, 13h05   #5
po_boy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Deleting Files and folders

Thanks. I will keep working on it.

"Jeffery Hicks [MVP]" wrote:

> I don't have time to write you a complete script. Basically you need to do
> something like this:
>
> On Error Resume Next
> strFolder="f:\data"
> Call DeleteOldFiles(strFolder)
>
> wscript.quit 'end main script
>
> Sub DeleteOldFiles(strFolder)
> Set objFSO=CreateObject("Scripting.FileSystemObject")
> Set objFolder=objFSO.GetFolder(strFolder)
> Set colFiles=objFolder.Files
> For Each file In colFiles
> If Int(DateDiff("d",file.DateLastModified,Now)) >= 60 Then
> WScript.Echo "Deleting " & file & " (" &_
> file.DateLastModified & ")"
> objFSO.DeleteFile file,True
> If Err.Number<>0 Then
> WScript.Echo "**Failed to delete " & file & ". Error# " &_
> Err.Number & " " & Err.Description & "**"
> End If
> End If
> Next
> Set colSubs=-objFolder.SubFolders
> For Each subFldr In colSubs
> Call DeleteOldFiles(subFldr)
> next
> end sub
> 'end of script
>
> I strongly suggest you pick up one or two books on scripting. I always
> recommend VBScript, WMI and ADSI Unleashed by Don Jones as a good tutorial.
> My WSH and VBScript Core: TFM is a complete language reference with
> real-world and practical examples of every object, function, method,
> property and statement you are likely to need in VBScript.
>
> --
> Jeffery Hicks
> Microsoft PowerShell MVP
> http://www.scriptinganswers.com
> http://www.powershellcommunity.org
>
> Now Available: WSH and VBScript Core: TFM
> Coming Soon: Windows PowerShell: TFM 2nd Ed.
> "po_boy" <poboy@discussions.microsoft.com> wrote in message
> news:0C9E58D5-98D5-4535-B406-B5DD7EAF1998@microsoft.com...
> > Thanks Jeffery, but that is the problem. I am not versed enought in
> > functions
> > to make it delete the sub-folders and or files.
> >
> > "Jeffery Hicks [MVP]" wrote:
> >
> >> See if this s get you in the right direction.
> >>
> >> On Error Resume Next

> strFolder="f:\data"
> >> Set objFSO=CreateObject("Scripting.FileSystemObject")
> >> Set objFolder=objFSO.GetFolder(strFolder)
> >> Set colFiles=objFolder.Files
> >> For Each file In colFiles
> >> If Int(DateDiff("d",file.DateLastModified,Now)) >= 60 Then
> >> WScript.Echo "Deleting " & file & " (" &_
> >> file.DateLastModified & ")"
> >> objFSO.DeleteFile file,True
> >> If Err.Number<>0 Then
> >> WScript.Echo "**Failed to delete " & file & ". Error# " &_
> >> Err.Number & " " & Err.Description & "**"
> >> End If
> >> End If
> >> Next
> >> 'end of script
> >>
> >> This script finds all files in F:\Data that are > 60 days old based on
> >> date
> >> last modified and deletes them. You could take this code and create a
> >> function so you could recurse through subfolders.
> >>
> >> --
> >> Jeffery Hicks
> >> Microsoft PowerShell MVP
> >> http://www.scriptinganswers.com
> >> http://www.powershellcommunity.org
> >>
> >> Now Available: WSH and VBScript Core: TFM
> >> Coming Soon: Windows PowerShell: TFM 2nd Ed.
> >>
> >> "po_boy" <poboy@discussions.microsoft.com> wrote in message
> >> newsDFA0136-97B9-4D00-B847-0614060EF44F@microsoft.com...
> >> >I have some files and folders under C:\LogFiles. This folder has many
> >> > subfolders and files. I need to find an easy way to delete the files or
> >> > folders(subfolder) that are older than X days. Most scripts only do a
> >> > folder
> >> > and files but not a group and since I am not that good with scripts it
> >> > is
> >> > not
> >> > working well for my needs. Please assist.
> >>

>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h56.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18719 seconds with 13 queries