Forum

scrip ile klasö...
 
Bildirimler
Hepsini Temizle

scrip ile klasör içersindeki dosyaları silmek

5 Yazılar
3 Üyeler
0 Likes
556 Görüntüleme
(@nasrineymar)
Gönderiler: 103
Reputable Member
Konu başlatıcı
 

Merhaba Arkadaşlar,

Ortamda bir adet PERSON2015 adında Server bulunmaktadır.

Bu server'in E diskinin altında DATA adında bir klasör mevcut. Bu klasör günlük doluyor yani Server'a çalışan uygulama bu DATA adındaki klasörü devamlı kapasitesini yükselktmektedir.

Server'in E: diskinin altındaki DATA adlı Klasörünün içindeki dosyaları otomatik bir script ile nasıl silebilirim ve bu script'i scheduled task ile çalıştırmak istiyordum.

Yani özet olarak,

Server'in E diskindeki DATA klasöründe yer alan dosyalar 10 günden eski ise silinsin. Bunu script ile nasıl yapabilirim? Bununla ilgili elinizde script bulunur mu?

Server Adı: PERSON2015

Server OS : Windows Server 2012 R2 X64

Silinecek dosya adresi. E:\DATA\

Bilgilerinize sunar iyi günler dilerim.

Saygılar

Kenan

 
Gönderildi : 13/04/2015 16:43

(@muratgok)
Gönderiler: 220
Reputable Member
 

Bunu bir deneyin

 

 

Start of Code *******************

Option Explicit
On Error Resume Next
Dim oFSO, oFolder, sDirectoryPath
Dim oFileCollection, oFile, sDir
Dim iDaysOld

' Specify Directory Path From Where You want to clear the old files

sDirectoryPath = "C:\MyFolder"

' Specify Number of Days Old File to Delete

iDaysOld = 15

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files

For each oFile in oFileCollection

'This section will filter the log file as I have used for for test case
'Specify the Extension of file that you want to delete
'and the number with Number of character in the file extension
    
    If LCase(Right(Cstr(oFile.Name), 3)) = "log" Then
     
         If oFile.DateLastModified < (Date() - iDaysOld) Then
         oFile.Delete(True)
         End If
 
    End If   
Next

Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing

'********** End of Code ****************

 
Gönderildi : 13/04/2015 16:54

(@nasrineymar)
Gönderiler: 103
Reputable Member
Konu başlatıcı
 

windows Cannot fid 'of'. Make sure you typed the name correctly, and then try again. hata mesajı vermiş olup ve sonrasında OK butonuna bastığımda ise CMD ekranında aşağıdaki loglar gelmekktedir.

C:\Scripts>deletefiles.bat

C:\Scripts>Start of Code **********************
The system cannot find the file of.

C:\Scripts>Option Explicit
'Option' is not recognized as an internal or external command,
operable program or batch file.

C:\Scripts>On Error Resume Next
'On' is not recognized as an internal or external command,
operable program or batch file.

C:\Scripts>Dim oFSO, oFolder, sDirectoryPath
'Dim' is not recognized as an internal or external command,
operable program or batch file.

C:\Scripts>Dim oFileCollection, oFile, sDir
'Dim' is not recognized as an internal or external command,
operable program or batch file.

C:\Scripts>Dim iDaysOld
'Dim' is not recognized as an internal or external command,
operable program or batch file.

C:\Scripts>' Specify Directory Path From Where You want to clear the old files
''' is not recognized as an internal or external command,
operable program or batch file.

C:\Scripts>sDirectoryPath = "C:\MyFolder"
'sDirectoryPath' is not recognized as an internal or external command,
operable program or batch file.

C:\Scripts>' Specify Number of Days Old File to Delete
''' is not recognized as an internal or external command,
operable program or batch file.

C:\Scripts>iDaysOld = 15
'iDaysOld' is not recognized as an internal or external command,
operable program or batch file.

C:\Scripts>Set oFSO = CreateObject("Scripting.FileSystemObject")

C:\Scripts>Set oFolder = oFSO.GetFolder(sDirectoryPath)

C:\Scripts>Set oFileCollection = oFolder.Files
each was unexpected at this time.
C:\Scripts>For each oFile in oFileCollection
C:\Scripts>

Saygılar Hocam

 

 

 
Gönderildi : 14/04/2015 11:58

(@muratgok)
Gönderiler: 220
Reputable Member
 

Kod aşağıdaki şekilde çalışmıştır. .vbs olarak kaydedip deneyebilirisniz. 

c/deneme altında 3 günden eski tüm dosyaları silinmektedir.

kolay gelsin

 

Option Explicit
On Error Resume Next
Dim oFSO, oFolder, sDirectoryPath
Dim oFileCollection, oFile, sDir
Dim iDaysOld

' Specify Directory Path From Where You want to clear the old files

sDirectoryPath = "C:\deneme"

' Specify Number of Days Old File to Delete

iDaysOld = 3

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files

For each oFile in oFileCollection

'This section will filter the log file as I have used for for test case
'Specify the Extension of file that you want to delete
'and the number with Number of character in the file extension
    
     
         If oFile.DateLastModified < (Date() - iDaysOld) Then
         oFile.Delete(True)
         End If
 
     
Next

Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing

 
Gönderildi : 14/04/2015 12:52

(@OzcanSAHIN)
Gönderiler: 198
Estimable Member
 

Kenan Bey,

Ayni soru için birden fazla post açmaniz forum kurallarina aykiri.

Diger açmis oldugunuz post' ta ki cevap isinizi gorecektir.

http://www.cozumpark.com/forums/thread/461267.aspx

 Kolay gelsin

 
Gönderildi : 14/04/2015 13:06

Paylaş: