PC Review


Reply
Thread Tools Rate Thread

Batch emptying a selection of folders?

 
 
googleicq@yahoo.com
Guest
Posts: n/a
 
      9th Jun 2008
Can someone please tell me how I can delete the files from 100+
folders *without opening each one*, selecting all the files and then
deleting them?

TIA!
 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      9th Jun 2008

<(E-Mail Removed)> wrote in message
news:821651a4-3612-4c78-a8fc-(E-Mail Removed)...
> Can someone please tell me how I can delete the files from 100+
> folders *without opening each one*, selecting all the files and then
> deleting them?
>
> TIA!


You could right-click each of the folders, then press the Delete
key on your keyboard.

When you say "Batch", are you thinking of a batch file program?
If so then you need to post exactly where your 100+ folders
reside and how the batch file would "know" which ones to delete.


 
Reply With Quote
 
John John (MVP)
Guest
Posts: n/a
 
      9th Jun 2008
(E-Mail Removed) wrote:

> Can someone please tell me how I can delete the files from 100+
> folders *without opening each one*, selecting all the files and then
> deleting them?
>
> TIA!


What does the directory structure look like? Are all the folders under
one tree and do you want to delete all the files in all the folders in
the tree? Or are the folders all over the place, or do you want to only
delete files in select folders in a tree and leave files in other folders?

John
 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      9th Jun 2008

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Mon, 9 Jun 2008 12:23:38 +0200, "Pegasus \(MVP\)"
> <(E-Mail Removed)> wrote:
>
>>You could right-click each of the folders, then press the Delete
>>key on your keyboard.

>
>
> It is my understanding that when you press Delete after
> right-clicking a folder, you delete the *folder* plus its contents.
>
>
>>When you say "Batch", are you thinking of a batch file program?
>>If so then you need to post exactly where your 100+ folders
>>reside and how the batch file would "know" which ones to delete.

>
> Yes I am thinking about perhaps a batch file (.bat).
> The folders all reside under one other folder.
>
> Again, I don't want to delete entire folders, just their contents.
> Knowing which folders to leave alone would be the tricky part, because
> this is changed each time I need to go through this exercise.
>
> So of approx. 100 folders, I'd like to keep the files in approx.
> 10-20.
>


Unless you can spell out a rule that says which folder should
be retained (or which ones should be deleted), a batch file
solution is not feasible.


 
Reply With Quote
 
Twayne
Guest
Posts: n/a
 
      9th Jun 2008
> On Mon, 9 Jun 2008 22:22:48 +0200, "Pegasus \(MVP\)"
> <(E-Mail Removed)> wrote:
>>
>> Unless you can spell out a rule that says which folder should
>> be retained (or which ones should be deleted), a batch file
>> solution is not feasible.

>
>
> OK.
>
> Well in my initial post I wasn't necessarily looking for a 'batch
> file' solution. I thought perhaps I could go this route.
>
> I was looking for some software solution that would do the job on a
> 'batch' of folders.
>
> Would you have any suggestions for a software solution?
>
> If I selected all the folders and then de-selected the ones I wanted
> left alone, is there some way to have the *contents* of the selected
> folders deleted, all at the same time?
>
> TIA


That would work. And when you have a folder selected and issue a
Delete, that folder and ALL of its contents will be deleted. If that's
what you want, it saves picking out files in the folder; just choose the
folder itself, but realize, the folder itself will also be deleted.

I'm not so sure your question if fully understood; but that's how I read
it.

Twayne


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      9th Jun 2008

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Mon, 9 Jun 2008 22:22:48 +0200, "Pegasus \(MVP\)"
> <(E-Mail Removed)> wrote:
>>
>>Unless you can spell out a rule that says which folder should
>>be retained (or which ones should be deleted), a batch file
>>solution is not feasible.

>
>
> OK.
>
> Well in my initial post I wasn't necessarily looking for a 'batch
> file' solution. I thought perhaps I could go this route.
>
> I was looking for some software solution that would do the job on a
> 'batch' of folders.
>
> Would you have any suggestions for a software solution?
>
> If I selected all the folders and then de-selected the ones I wanted
> left alone, is there some way to have the *contents* of the selected
> folders deleted, all at the same time?
>
> TIA


The way to do this would be to create an extra option that
becomes visible when right-clicking one of the selected files,
and linking it to a batch file that performs the job. Unfortunately
I am not sufficiently familiar with the technique to shake it out
of my sleeve.


 
Reply With Quote
 
John John (MVP)
Guest
Posts: n/a
 
      10th Jun 2008
(E-Mail Removed) wrote:

> On Mon, 09 Jun 2008 07:48:50 -0300, "John John (MVP)"
> <(E-Mail Removed)> wrote:
>
>
>>What does the directory structure look like? Are all the folders under
>>one tree and do you want to delete all the files in all the folders in
>>the tree? Or are the folders all over the place, or do you want to only
>>delete files in select folders in a tree and leave files in other folders?
>>
>>John

>
>
>
> Yes all the folders are under one tree.
> No I don't want to delete all the files in all the folders.
> Yes, I want to delete files in select folders in a tree and leave
> files in other folders in that tree.
>
> I'm hoping there can be a batch file written or some other painless
> way of deleting all of these files.
>
> Maybe selecting all the folders in the tree, and then de-selecting the
> ones (just a few ) whose file I want to keep?
>
> TIA!


If this is a one time affair it's probably easier to delete the files
manually. If the directory structure is only one sub-folder deep it can
be pretty easy to do in a semi-automatic way, if the folders are nested
several folders deep it will be a bit harder.

You have to create a base list of folders to work with. The basis for
the command is easy to grasp and completely safe to test by issuing the
following commands at the command prompt:

Using the CD command navigate to your desired starting folder and issue:

dir /ad /b /s >c:\dirlist.txt

Then issue:

for /f "usebackq delims=" %A in ("c:\dirlist.txt") do echo "%A"

Now you understand what you have to do. Change the echo command in the
above line with your favorite commands and you will be able to do what
you want. Be careful with this, test on sample folders first and make
sure that you have backups before you proceed! Files deleted at the
command prompt do not go to the Recycle Bin, they are permanently deleted!

If the folders are only one folder deep inside a base directory, like such:

D:\Test\Test1
D:\Test\Test2
D:\Test\Test3
D:\Test\Test4
D:\Test\Test5

and if the files to delete are only in the numbered Test folders then
you can simply:

1- Create a folder list.

Using the CD command navigate to D:\Test and issue:

dir /b /ad /s >d:\dirlist.txt


2- Manually delete the numbered test folders as needed.

3- Issue:

for /f "usebackq delims=" %A in ("d:\dirlist.txt") do md "%A"

This will create new empty directories to replace the ones you have
manually deleted, the folders and files which were not deleted will be
unaffected and the directory structure will be restored.

In the second example let's assume that you want to only keep the files
in the Test1 folder and delete all the files in the other numbered Test
folders.

1- Create a folder list.

Navigate to D:\Test and issue:

dir /b /ad /s >d:\dirlist.txt


2- Edit the dirlist.txt file so that it contains only the folders to be
deleted:

D:\Test\Test2
D:\Test\Test3
D:\Test\Test4
D:\Test\Test5


3- Issue the RD command against the folder list:

for /f "usebackq delims=" %A in ("d:\dirlist.txt") do rd /s /q "%A"

This will delete all but the Test\Test1 folder.


4- Issue the MD command to recreate the deleted folders:

for /f "usebackq delims=" %A in ("d:\dirlist.txt") do md "%A"

As explained in the last example below you could also do this with this
command at step 3 and forgo step 4:

for /f "usebackq delims=" %A in ("d:\dirlist.txt") do del "%A\*.*" /q


In this last example lets change the directory structure so that it is
deeper than one sub-directory and lets assume files may be in any folder
in the structure. The folder structure is like so:

D:\Test\Test1\Folder 1
D:\Test\Test2\Folder 2
D:\Test\Test3\Folder 3
D:\Test\Test4\Folder 4
D:\Test\Test5\Folder 5

Lets assume that all of the folders and sub-folders contain files and
that we want to delete all the files only in the following directories:

D:\Test
D:\Test\Test3
D:\Test\Test5\Folder 5

Once again we use the dir command to create the folder list and then we
edit the file so that it only contains the above mentioned folders.

However, we cannot globally use the RD command against the list as it
would also delete sub-folders which contain files that we want to keep.
Instead we use the DEL command with wildcard characters:

for /f "usebackq delims=" %A in ("d:\dirlist.txt") do del "%A\*.*" /q

This will delete all files in the folders in the list only, it will not
delete directories or files in other folders.

Don't try to use the RD command from a folder to be deleted. This was
tested at the Command Prompt, in a batch file double up the %:

for /f "usebackq delims=" %%A in ("d:\dirlist.txt") do md "%%A"

Use with care, make sure you have backups and pay attention to what you
are doing. No one but you can be held responsible if you delete all
your important files!

John

 
Reply With Quote
 
John John (MVP)
Guest
Posts: n/a
 
      10th Jun 2008
(E-Mail Removed) wrote:

> On Mon, 09 Jun 2008 21:46:38 -0300, "John John (MVP)"
>
>>If this is a one time affair it's probably easier to delete the files
>>manually. If the directory structure is only one sub-folder deep it can
>>be pretty easy to do in a semi-automatic way, if the folders are nested
>>several folders deep it will be a bit harder.

>
>
>
> No it's not a one time affair. I'd need to run it every few months.
> Yes the directory structure is just one sub-folder deep.
>
>
> Your commands look great! Thanks very much!
>
> I set up some test folders and files and just gave it a run through.
> I can get the dirlist OK but the step after that isn't working.
>
> Here's the message I'm getting at the DOS prompt:
>
> E:\Test>mdbat
> \test\dirlist.txt") do md "A" was unexpected at this time.
> E:\Test>for /f "usebackq delims=" \test\dirlist.txt") do md "A"



It works fine here, this is the output at the Command Prompt:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>

C:\>cd drivers

C:\DRIVERS>dir /ad /b /s >c:\dirlist.txt

C:\DRIVERS>cd\

C:\>for /f "usebackq delims=" %A in ("c:\dirlist.txt") do echo "%A"

C:\>echo "C:\DRIVERS\AUDIO"
"C:\DRIVERS\AUDIO"

C:\>echo "C:\DRIVERS\MODEM"
"C:\DRIVERS\MODEM"

C:\>echo "C:\DRIVERS\MOUSE"
"C:\DRIVERS\MOUSE"

C:\>echo "C:\DRIVERS\NETWORK"
"C:\DRIVERS\NETWORK"

C:\>echo "C:\DRIVERS\NETWORK2"
"C:\DRIVERS\NETWORK2"

C:\>echo "C:\DRIVERS\OTHER"
"C:\DRIVERS\OTHER"

C:\>echo "C:\DRIVERS\OTHER2"
"C:\DRIVERS\OTHER2"

C:\>echo "C:\DRIVERS\OTHER3"
"C:\DRIVERS\OTHER3"

C:\>echo "C:\DRIVERS\VIDEO"
"C:\DRIVERS\VIDEO"

C:\>echo "C:\DRIVERS\WLAN"
"C:\DRIVERS\WLAN"


I suggest that you copy and paste to avoid syntax errors. Try the above
at a Command Prompt. Your error is replicated below when the first %
sign is omitted from the command:

C:\>
C:\>for /f "usebackq delims=" A in ("c:\dirlist.txt") do echo "%A"
A was unexpected at this time.
C:\>

Don't forget, in a batch file you have to double up the % in the commands:

for /f "usebackq delims=" %%A in ("c:\dirlist.txt") do echo "%%A"

John
 
Reply With Quote
 
John John (MVP)
Guest
Posts: n/a
 
      10th Jun 2008
(E-Mail Removed) wrote:

> On Mon, 09 Jun 2008 21:46:38 -0300, "John John (MVP)"
>
>
> Hi John,
>
> I was anxious to try the creation of the dirlist on my actual folders
> and just tried it now.
> It works just fine, but what would the command be to have the
> subfolders listed in alpha order?
>
> Most of the subfolders are first last name, so sorting by
> last name would be nice (sorting by first name would be my second
> choice).
>
> here's what it's like now:
> E:\Jazz\Lage Lund
> E:\Jazz\John Stowell
> E:\Jazz\Adam Rogers
> E:\Jazz\Oliver Nelson
> E:\Jazz\Jack Wilkins
> E:\Jazz\Dan Hicks
> etc.
>
> Thanks again!


At the command prompt do: dir /?

Look at the /O switch.

dir /ad /b /O:N /s >c:\dirlist.txt

John
 
Reply With Quote
 
John John (MVP)
Guest
Posts: n/a
 
      11th Jun 2008
(E-Mail Removed) wrote:

> On Tue, 10 Jun 2008 00:03:21 -0300, "John John (MVP)"
>
>
>>Don't forget, in a batch file you have to double up the % in the commands:
>>
>>for /f "usebackq delims=" %%A in ("c:\dirlist.txt") do echo "%%A"

>
>
>
> Thanks John, that was my mistake. I forgot to add an extra % for
> the .bat file.
>
> It works perfectly! I tested it and also used it on my actual
> folders/files.
>
> Thanks again, I really appreciate it. This will be a big time saver!


You're welcome.

John
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove confirmation notice on emptying folders Barry Windows Vista Mail 4 5th Mar 2008 08:25 AM
My inbox and other folders keep emptying of mails =?Utf-8?B?c2FtbWFj?= Microsoft Outlook Discussion 2 9th Dec 2005 05:54 PM
Emptying DLL cache and Prefetch folders? Kenny Windows XP Basics 1 30th Nov 2003 11:56 PM
Emptying Temp folders Bill Windows XP Internet Explorer 5 22nd Sep 2003 01:16 AM
Bizarre sudden emptying of OE newsgroup folders LuckyStrike Windows XP Internet Explorer 0 15th Sep 2003 10:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:28 AM.