VBScript for delete files

Archived from groups: microsoft.public.win2000.setup_deployment (More info?)

dear gurus,

I would need a vbscript which delete all the files of a set of folders.

Does anyone know how could i do such thing?
regards,
6 answers Last reply
More about vbscript delete files
  1. Archived from groups: microsoft.public.win2000.setup_deployment (More info?)

    Hi,

    There's two options, you can either delete the folder at the top of the
    tree (thereby deleting everything below it), or you can delete specific
    files. The WSH object is called the FileSystemObject and can be used
    with VBSciprt and JScript.

    Enric wrote:

    > dear gurus,
    >
    > I would need a vbscript which delete all the files of a set of folders.
    >
    > Does anyone know how could i do such thing?
    > regards,


    --
    Gerry Hickman (London UK)
  2. Archived from groups: microsoft.public.win2000.setup_deployment (More info?)

    Thanks Gerry,

    But I was wondering how can I do a loop in the top folder (foldergeneral) in
    order to check out every folder and once there, delete the specified files?

    \\folder1\foldergeneral\1
    \\folder1\foldergeneral\2
    \\folder1\foldergeneral\3
    \\folder1\foldergeneral\4

    Best regards,

    "Gerry Hickman" wrote:

    > Hi,
    >
    > There's two options, you can either delete the folder at the top of the
    > tree (thereby deleting everything below it), or you can delete specific
    > files. The WSH object is called the FileSystemObject and can be used
    > with VBSciprt and JScript.
    >
    > Enric wrote:
    >
    > > dear gurus,
    > >
    > > I would need a vbscript which delete all the files of a set of folders.
    > >
    > > Does anyone know how could i do such thing?
    > > regards,
    >
    >
    > --
    > Gerry Hickman (London UK)
    >
  3. Archived from groups: microsoft.public.win2000.setup_deployment (More info?)

    Hi Enric,

    Well you wanted one thing, and now you want something different -
    enumeration of folders and testing of files before deletion. In general
    this is done using recursion with the SubFolders collection of the
    Folder object of the FileSystemObject, or you can use WMI if you don't
    care about UNC paths.

    For full details and examples, you may want to post about this in the
    WSH newsgroup on this server.

    If you want advanced programming examples, you may want to post in the
    WMI newsgroup on this server.

    > Thanks Gerry,
    >
    > But I was wondering how can I do a loop in the top folder (foldergeneral) in
    > order to check out every folder and once there, delete the specified files?
    >
    > \\folder1\foldergeneral\1
    > \\folder1\foldergeneral\2
    > \\folder1\foldergeneral\3
    > \\folder1\foldergeneral\4
    >
    > Best regards,
    >
    > "Gerry Hickman" wrote:
    >
    >
    >>Hi,
    >>
    >>There's two options, you can either delete the folder at the top of the
    >>tree (thereby deleting everything below it), or you can delete specific
    >>files. The WSH object is called the FileSystemObject and can be used
    >>with VBSciprt and JScript.
    >>
    >>Enric wrote:
    >>
    >>
    >>>dear gurus,
    >>>
    >>>I would need a vbscript which delete all the files of a set of folders.
    >>>
    >>>Does anyone know how could i do such thing?
    >>>regards,
    >>
    >>
    >>--
    >>Gerry Hickman (London UK)
    >>


    --
    Gerry Hickman (London UK)
  4. 'Delete specified folder and subfolders
    'Atention!!! Files or folders will not be saved in Recycle Bin
    strFolderPath="C:\New Folder"


    Set fso=CreateObject("Scripting.FileSystemObject")


    If fso.FolderExists(strFolderPath) Then
    set demofolder = fso.GetFolder(strFolderPath)

    'The True parameter remove the folder forcefully
    fso.DeleteFolder strFolderPath, True 'Delete the copied folder
    'fso.CreateFolder strFolderPath 'Create a new folder with the name specified in variable
    'fso.DeleteFolder(strFolderPath) 'Another method for delete
    WScript.Echo "Deleted folder!!!"
    else
    WScript.Echo "Inexistent folder!!!"
    End If

    'Enjoy
  5. This work great for me but I wanted to create a vbs script like this but it will delete the recent files and folder added.. Suppose like in my computer or network computer in the directory of C:\Documents and Settings\All Users\Start Menu\Programs I have many programs installed I want only the NEW FOLDERS AND FILES added be deleted and the old folders be remind.

    Can you please help me on this? Thanks

    unlawful_pub


    euelvis said:
    'Delete specified folder and subfolders
    'Atention!!! Files or folders will not be saved in Recycle Bin
    strFolderPath="C:\New Folder"


    Set fso=CreateObject("Scripting.FileSystemObject")


    If fso.FolderExists(strFolderPath) Then
    set demofolder = fso.GetFolder(strFolderPath)

    'The True parameter remove the folder forcefully
    fso.DeleteFolder strFolderPath, True 'Delete the copied folder
    'fso.CreateFolder strFolderPath 'Create a new folder with the name specified in variable
    'fso.DeleteFolder(strFolderPath) 'Another method for delete
    WScript.Echo "Deleted folder!!!"
    else
    WScript.Echo "Inexistent folder!!!"
    End If

    'Enjoy
  6. unlawful_pub said:
    This work great for me but I wanted to create a vbs script like this but it will delete the recent files and folder added.. Suppose like in my computer or network computer in the directory of C:\Documents and Settings\All Users\Start Menu\Programs I have many programs installed I want only the NEW FOLDERS AND FILES added be deleted and the old folders be remind.

    Can you please help me on this? Thanks

    unlawful_pub


    'Delete specified subfolders after a specified target date
    'Atention!!! Files or folders will not be saved in Recycle Bin
    'In your case is strFolderPath=C:\Documents and Settings\All Users\Start Menu\Programs

    strFolderPath="C:\New Folder"
    strComputer="."
    yourdate=CDate("2011-03-14 20:30:00")
    Set fso=CreateObject("Scripting.FileSystemObject" )

    If fso.FolderExists(strFolderPath) Then
    set demofolder = fso.GetFolder(strFolderPath)
    strSubFolderPath=""
    Set colSubfolders = demofolder.Subfolders
    For Each objSubfolder in colSubfolders
    If FormatDateTime(objSubfolder.DateCreated) >= FormatDateTime(yourdate) Then
    'Wscript.Echo objSubfolder.Name, objSubfolder.Size _
    '& VbCrlf & "Date created: " & objSubfolder.DateCreated
    strSubFolderPath= strFolderPath & "\" & objSubfolder.Name
    fso.DeleteFolder strSubFolderPath, True 'Delete the subfolder
    WScript.Echo "The SubFolder " & strSubFolderPath & " was deleted!!!"
    End If
    Next

    'The True parameter remove the folder forcefully
    'fso.DeleteFolder strFolderPath, True 'Delete the copied folder

    'fso.CreateFolder strFolderPath 'Create a new folder with the name specified in variable
    'fso.DeleteFolder(strFolderPath) 'Another method for delete

    else
    WScript.Echo "Inexistent folder!!!"
    End If

    WScript.Quit

    Hope is helpul.
Ask a new question

Read More

VBScript Microsoft Windows