• 0

How do I delete files ?


Question

I have a root folder.

This root folder has many sub-folders in it.

In each sub-folder there is a .config folder

I am looking for a tool which will delete all files ( but not sub-folders) with .config folder.

How do I make it ?

In simple words ..

Input:

root folder

Output:

root folder with sub-folders including .config folder.

There is no files in any of the sub-folders excluding .config folder.

Its windows XP + SP2 Operating System

Link to comment
Share on other sites

20 answers to this question

Recommended Posts

  • 0

Its windows XP + SP2 Operating System

I think, you need to do it manually, the easier way is to open the root directory in Tree Explorer ..

I can not do it manually. there are hundreds of sub-folders and hundreds of files . I need the help of a tool

Thank god, I thought I was losing my marbles!

Although in that one he wanted to delete the .config files, and now he wants to save them? What's this for, some kind of school project?

Objectives are different. For your information, Its related to synchronization. This post is a simplified version of my complicated original requirement .

I'll be happy if you please tell me a workaround to this post

Link to comment
Share on other sites

  • 0

Its windows XP + SP2 Operating System

I can not do it manually. there are hundreds of sub-folders and hundreds of files . I need the help of a tool

In that case use Xcopy Trick ;)

XCOPY /S /EXCLUDE : file1 [+file2] [+file3] . . .

Link to comment
Share on other sites

  • 0

copy ? I want to delete files ! Please read my requirement again.

God! do i have to explain that simple thing too ?

When you finished copy with your .config files, just delete the Original directory !

Link to comment
Share on other sites

  • 0

copy ? I want to delete files ! Please read my requirement again.

He did, and XCOPY would work I think. Using the XCOPY command, copy the .config files including directories and subdirectories to another location, then just delete the original files and folders. Done.

Link to comment
Share on other sites

  • 0

Thanks . However I was looking at http://www.microsoft...y.mspx?mfr=true

But I'm still not sure how this can serve my purpose.

Link says ..

/exclude:filename1[+[filename2]][+[filename3]]: Specifies a list of files containing strings.

My requirements is ,

..... which will delete all files ( but not sub-folders) with .config folder.

Are not you trying to say the files that i want to delete should be passed as parameters to /exclude ?

He did, and XCOPY would work I think. Using the XCOPY command, copy the .config files including directories and subdirectories to another location, then just delete the original files and folders. Done.

getting confused. Whats the complete command you are firing ? are you using exclude or not ?

Link to comment
Share on other sites

  • 0

Let me get this straight.

You want to delete all files and sub-folders in the root directory except the files within a ".config" directory... correct?

Backup the folder first but this should work. I tested it.

Copy the code and save it as a .vbs file.


On Error Resume Next
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
FindFolders "C:\MyRootFolder"
Function FindFolders(sFolder)
Dim oFolder, oSubFolders, folder
Set oFolder = oFSO.GetFolder(sFolder)
Set oSubFolders = oFolder.SubFolders
For Each folder In oSubFolders
If Not LCase(folder.name) = ".config" Then
FindFolders sFolder & "\" & folder.name
FindFiles sFolder & "\" & folder.name
End If
Next
End Function
Function FindFiles(sFolder)
Dim oFolder, oFile, file

Set oFolder = oFSO.GetFolder(sFolder)

If Not LCase(oFolder.Name) = ".config" Then

For Each file in oFolder.Files
Set oFile = oFSO.GetFile(sFolder & "\" & file.name)
oFSO.DeleteFile sFolder & "\" & file.name, true
Next
If oFolder.Folders.Count = 0 Then
oFSO.DeleteFolder sFolder
End If
End If
End Function
[/CODE]

Link to comment
Share on other sites

  • 0

Here is the most simple version ...

I want the following ..

1. delete all files under root and under all its sub-folders .

2. dont delete sub-folders.

3. dont delete .config folders .

Link to comment
Share on other sites

  • 0

Here is the most simple version ...

I want the following ..

1. delete all files under root and under all its sub-folders .

2. dont delete sub-folders.

3. dont delete .config folders .

Do you want to delete the contents of the .config folders or keep them?

On Error Resume Next
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")

FindFolders "C:\MyRootFolder"

Function FindFolders(sFolder)
Dim oFolder, oSubFolders, folder

Set oFolder = oFSO.GetFolder(sFolder)
Set oSubFolders = oFolder.SubFolders

For Each folder In oSubFolders
If Not LCase(folder.name) = ".config" Then
FindFolders sFolder & "\" & folder.name
FindFiles sFolder & "\" & folder.name
End If
Next
End Function

Function FindFiles(sFolder)
Dim oFolder, oFile, file

Set oFolder = oFSO.GetFolder(sFolder)

If Not LCase(oFolder.Name) = ".config" Then

For Each file in oFolder.Files
Set oFile = oFSO.GetFile(sFolder & "\" & file.name)
oFSO.DeleteFile sFolder & "\" & file.name, true
Next

End If
End Function

This will delete all folders in the root and subdirectory, keep sub directories, and not touch the .config folders in anyway.

But I stress, make a backup of the folder first just in case something goes wrong!

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.