# erase with directory wildcards

Discussion in 'Support' started by David Marcus, Sep 19, 2011.

1. ### David Marcus

Joined:
Jun 4, 2008
Messages:
648
1
Doing "erase **\.svn\**\*" causes TCC to disappear (after it asks if I'm sure).

Actually, I wanted to delete all the .svn directories, which I guess the above command wouldn't do (assuming TCC didn't crash). Will /X work with directory wildcards?

TCC 13.00.23 x64 Windows 7 [Version 6.1.7601]

2. ### David Marcus

Joined:
Jun 4, 2008
Messages:
648
1
Is this a confirmed bug?

3. ### rconn Administrator Staff Member

Joined:
May 14, 2008
Messages:
9,856
83
Not reproducible here.

I can't imagine what you're trying to do that that syntax, but it the result almost certainly wouldn't be what you intended. (Unless you're trying to delete files that are at least two subdirectories down from the .svn directories?)

/X will work with directory wildcards.

4. ### rconn Administrator Staff Member

Joined:
May 14, 2008
Messages:
9,856
83
You're asking for TCC to temporarily save all the info on every file in every directory on your drive, so depending on your system & the amount of files & memory you have, you could easily use up every scrap of RAM you have. (TCC will normally detect an out-of-memory error on its own memory allocations, but if it happens in an RTL function or a Windows API, it usually just crashes the app.)

I cannot think of any reason to have two directory wildcards in a wildcard spec (and you have three!).

5. ### David Marcus

Joined:
Jun 4, 2008
Messages:
648
1
I was trying to delete all directories named .svn, many of which contained files or directories. Is there a syntax that will do that?

Someone sent me a zip of their development folder. It had all these .svn directories at various levels down. I don't need them. So, I wanted to delete them. I ended up doing it in Epsilon (the text editor I use). It was pretty easy to do in Epsilon: A dired on **\.svn listed 237 directories. Holding down the "D" key marked them all for deletion. Pressing "X" told Epsilon to delete them. It asked me to confirm that I should delete them even though they weren't empty. Then it did it.

Am I? I thought it would just walk through the folder/file tree deleting things as it goes. (I actually ran the command from a sudirectory, not from c:\.)

6. ### rconn Administrator Staff Member

Joined:
May 14, 2008
Messages:
9,856
83
No, you told TCC to look in every subdirectory and all of their subdirectories for a directory named .svn. But TCC had to save every parent directory so it could back up and go down the next subdirectory tree.

Then, you told TCC that once it found a .svn directory, look in every one of its subdirectories for another subdirectory, and delete the files in that sub-subdirectory. (And TCC had to save each parent directory again.)

7. ### rconn Administrator Staff Member

Joined:
May 14, 2008
Messages:
9,856
83
Several, but not with a single DEL statement.

The problem is that first you're trying to delete files in any directory called .svn, which can be done with:

del **\.svn\

But the /X directory removal cannot be done while DEL is recursing into the directory, so it's handled when you've returned from deleting all of the files in all of the matching subdirectories. But then all the directory removal API has to work with is "**\.svn", which isn't going to match anything. So you'll need to do another pass to clean up empty subdirectories.

Or, you could do the same thing as your editor by redirecting DIR output to SELECT, and then deleting the marked directories.

8. ### David Marcus

Joined:
Jun 4, 2008
Messages:
648
1
I'm not following. That doesn't seem to do anything:

HTML:
C:\Junk>ffind /s *
C:\Junk\Sub
C:\Junk\Sub\.svn
C:\Junk\Sub\.svn\foo
C:\Junk\Sub\.svn\bar2.txt
C:\Junk\Sub\.svn\foo\bar.txt

5 files

C:\Junk>del **\.svn\
TCC: (Sys) The system cannot find the file specified.
"C:\Junk\Sub\.svn\"
0 files deleted

C:\Junk>del /e **\.svn\
0 files deleted

C:\Junk>
Do you mean for the second pass or to do the whole thing? I'm not sure what you mean.

The following is odd. Note the doubled backslashes:

HTML:
C:\Junk>ffind /s **\.svn\
C:\Junk\Sub\.svn\\foo
C:\Junk\Sub\.svn\\bar2.txt
C:\Junk\Sub\.svn\\foo\bar.txt
I don't quite understand the algorithm, but I guess the point is that TCC isn't just checking each file to see if its path matches the spec.

9. ### Charles Dye Super Moderator Staff Member

Joined:
May 20, 2008
Messages:
3,304
39
Code:
global /i if isdir .svn echo del /s /x /z .svn\

Not tested -- handle with care!

10. ### samintz Scott Mintz

Joined:
May 20, 2008
Messages:
1,189
11
I don't quite understand the end goal.
But if the desire is to remove all subdirectory trees named .svn,
starting from the current directory, then this should work:

for /a:d /h /r %d in (*) if '%@filename[%d]'
== '.svn' del /sexyz %d

I'd try it with "echo del /sexyz
%d" first to see which directories would be targeted.

-Scott

David Marcus <> wrote on
09/27/2011 06:35:48 PM:

files in any

tree.

the spec.

11. ### samintz Scott Mintz

Joined:
May 20, 2008
Messages:
1,189
11
If you wanted to start in a different directory
than the current one you could do this:

alias delsvn=for /a:d /h /r %1 %d in
(*) if %@filename[%d] == .svn echo del /sexyz %d

delsvn
delsvn c:\foo\bar
etc.

-Scott

samintz <> wrote on 09/27/2011
08:08:37 PM:

12. ### samintz Scott Mintz

Joined:
May 20, 2008
Messages:
1,189
11
Or alternatively, you could use DO instead
of FOR:

do d in /d"c:\foo\bar" /s
/a:d * (if %d == .svn echo del /sexyz %@full[%d])

-Scott

samintz <> wrote on 09/27/2011
08:18:11 PM:

13. ### Charles Dye Super Moderator Staff Member

Joined:
May 20, 2008
Messages:
3,304
39
Or maybe even:

alias delsvn=for /a:d /h /r %1 %d in ( .svn[] ) echo del /s /e /x /y /z %d

14. ### Steve Fabian

Joined:
May 20, 2008
Messages:
3,520
4
From: Charles Dye
| alias delsvn=for /a:d /h /r %1 %d in ( .svn[] ) echo del /s /e /x /y /z %d

I'd modify this a little more to take care of names with embeddes spaces, etc. (%1 is already guaranteed to be quoted if needed):

alias delsvn=for /a:d /h /r %1 %d in ( .svn[] ) echo del /s /e /x /y /z %@quote[%d]
--
Steve

15. ### David Marcus

Joined:
Jun 4, 2008
Messages:
648
1
I'd like to mention that while this is all very interesting, I did realize that I could come up with something involving FOR or GLOBAL to do what I wanted. But, since this was a one-time need, when a simple erase didn't work, it took me much less time to do it using Epsilon's dired than it would have taken me to be sure I had a correct TCC solution.

Using "rmdir /s **\.svn" might also work, but I'd have to test it first.

With Epsilon, it was obvious what Epsilon was about to delete, so no testing was needed.

16. ### Charles Dye Super Moderator Staff Member

Joined:
May 20, 2008
Messages:
3,304
39
You're right; the paths returned might contain spaces. Is there some advantage to using @QUOTE, as opposed to just putting quotes around the %d ?

17. ### Steve Fabian

Joined:
May 20, 2008
Messages:
3,520
4
From: Charles Dye
| Is there some
| advantage to using @QUOTE, as opposed to just putting quotes around
| the %d ?

In this instance - no. It's better coding practice in general because the value of the variable may already be quoted.

Of course, it would be nice if FOR and DO could be enhanced by an option to quote names requiring it; PDIR already has that feature, both for the "*" being used to pass the current filespec to a function, and the "q" suboption of the "f" reporting field. Likewise, all filename-valued internal variables and variable functions ought to have "autoquoting" variants.
--
Steve