mIRC Home    About    Download    Register    News    Help

Print Thread
Delete folder with files #254296 02/08/15 01:46 AM
Joined: Jul 2015
Posts: 42
J
Joveice Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jul 2015
Posts: 42
How do i delete all files in a folder and the folder?
rmdir stops becouse there is files in the folder.

Re: Delete folder with files [Re: Joveice] #254419 09/08/15 11:31 PM
Joined: Jul 2015
Posts: 42
J
Joveice Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jul 2015
Posts: 42
Bump
Anyone Please?
etc I need to delete C:\Folder\Folder2
Folder2 has random files in it
and with this command it deleted Folder2 and everything in it
rmdir stops becouse there is files in the folder.

Re: Delete folder with files [Re: Joveice] #254420 10/08/15 02:54 AM
Joined: Jan 2005
Posts: 188
Brax Offline
Vogon poet
Offline
Vogon poet
Joined: Jan 2005
Posts: 188
First delete the files in the folder and then folder.

To delete the file you have command
/remove [-b] <filename>

To get the filenames in directory you can use $findfile
For more info see
/help $findfile
/help File and Directory Identifiers


echo -a $signature
Re: Delete folder with files [Re: Joveice] #254421 10/08/15 03:01 AM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
@Brax: it can be tricky to delete all files of all the sub folder of a directory, you would need recursion on $findfile to do it.

Here is a nice COM object handling this for you:

Code:
alias delete_fullfolder {
.comopen a Scripting.FileSystemObject
if ($com(a,GetFolder,1,bstr*,$1-,dispatch* b)) && (!$comerr) noop $com(b,Delete,1)
if ($com(a)) .comclose a
if ($com(b)) .comclose b
}
/delete_fullfolder <path> -- do not use quote.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Delete folder with files [Re: Wims] #254424 10/08/15 07:34 AM
Joined: Jan 2005
Posts: 188
Brax Offline
Vogon poet
Offline
Vogon poet
Joined: Jan 2005
Posts: 188
Recursion or not, it is still one way to do it. wink

But then again... all roads are supposed to lead to Rome.


echo -a $signature
Re: Delete folder with files [Re: Brax] #254430 10/08/15 11:42 AM
Joined: Jul 2015
Posts: 42
J
Joveice Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jul 2015
Posts: 42
the folder contains random files each time :P

Re: Delete folder with files [Re: Brax] #254433 10/08/15 02:21 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
Lol, not at all wink if recursion is involved you cannot do it in mIRC, or it would work for 100 files, but if you have sub folder with hundred of files it would never work


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Delete folder with files [Re: Wims] #254434 10/08/15 03:25 PM
Joined: Jul 2015
Posts: 42
J
Joveice Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jul 2015
Posts: 42
the folder got 5 text documents with random name, and i need it to delete the whole folder and everything inside of it :P thats what i would like :P

Re: Delete folder with files [Re: Joveice] #254435 10/08/15 04:18 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
Yeah, did you try the code I gave?


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Delete folder with files [Re: Wims] #254438 10/08/15 08:03 PM
Joined: Jul 2015
Posts: 42
J
Joveice Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jul 2015
Posts: 42
not yet, will when im back at the home server

Re: Delete folder with files [Re: Wims] #254443 11/08/15 12:35 AM
Joined: Jan 2005
Posts: 188
Brax Offline
Vogon poet
Offline
Vogon poet
Joined: Jan 2005
Posts: 188
I havent tried but it got me curious.
Can you explain why it wouldnt work with subfolders with hundreds of files?

Least at first glance and without trying it doesnt look impossible. Why couldnt I just loop over all the folders and subfolders, delete the files in them and remove the folders afterwards?

Leaving possible performance issues aside, wouldnt it still work?


echo -a $signature
Re: Delete folder with files [Re: Brax] #254444 11/08/15 01:17 AM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
I somewhat explained when I said it was about recursion, but the real reason is probably a memory issue.

Well our function must remove all files in the folder, look for all subfolders, and remove all files in that sub folder, then look for all subsubfolder in that subfolder, etc etc, so the main function is actually just a function removing all files in the directory, then calling itself for all the subfolder, and then removing that directory (you can't do it before looking for all subfolders), this is recursion:

/remfolder main_folder :
Code:
alias remfolder {
;get all directory in folder $1-
noop $finddir($1-,*,0,remfolder $1-)
rmdir $1-
}
It may be possible to write a procedural script (no recursion) but good luck with that.
And mIRC don't like recursion much, testing using something like this to create a lot of subfolders (/testf):
Code:
alias testf {
  var %a
  mkdir main_folder
  var %b 20
  while (%b) {
    %a = 8
     %d = main_folder
    while (%a) {
      %d = %d $+ \folder $+ %a $+ %b 
      mkdir $qt(%d)
      dec %a
    }
    dec %b
  }
}
executing /remfolder main_folder after that, I get an error (I'm on the latest 7.42, not 7.43 but it doesn't matter much) on /rmdir on a folder, if you try right away to delete that folder, with the exact same /rmdir command, it will work, suggesting no memory is available to do the operation, or something, I don't really know.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Delete folder with files [Re: Wims] #254446 11/08/15 03:00 AM
Joined: Jan 2005
Posts: 188
Brax Offline
Vogon poet
Offline
Vogon poet
Joined: Jan 2005
Posts: 188
Okay. I will play around with it someday to see what I can come up with, if I have too much free time laugh

Just that from initial look it seemed like it shouldnt be too complicated to do with some long looping.


echo -a $signature
Re: Delete folder with files [Re: Brax] #254451 11/08/15 01:50 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
Yeah, it always seems easier when you don't actually try it laugh


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Delete folder with files [Re: Wims] #254535 14/08/15 11:01 PM
Joined: May 2010
Posts: 29
P
Plornt Offline
Ameglian cow
Offline
Ameglian cow
P
Joined: May 2010
Posts: 29
Not tried it, but how about just invoking the systems delete with "/run"?


For example:

Code:
//run cmd.exe /c del /S /F /Q $mircdirtest


Just tested, it works great... So great I just accidentally deleted my mIRC directory haha (Oh god. Why wont recuva run.).

Last edited by Plornt; 14/08/15 11:19 PM.
Re: Delete folder with files [Re: Plornt] #254537 15/08/15 12:35 AM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
That works but /run is not going to wait for it to be done, mIRC will keep processing your code, just like with timer, being able to know when it's done might be just super useful.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Delete folder with files [Re: Wims] #254543 15/08/15 10:11 AM
Joined: May 2010
Posts: 29
P
Plornt Offline
Ameglian cow
Offline
Ameglian cow
P
Joined: May 2010
Posts: 29
Originally Posted By: Wims
That works but /run is not going to wait for it to be done, mIRC will keep processing your code, just like with timer, being able to know when it's done might be just super useful.


Ok true... So providing you are deleting the folder just to gain back the ability to write/read from it without clashing with the previous data you just deleted and are not wanting to know when its done to display some sort of progress. Couldnt you rename the directory before hand, and then use that command to delete? That way you can create a new directory with the old name as soon as the rename is done.

Probably a bit hacky but depending on what they are trying to do, it should work.

Re: Delete folder with files [Re: Plornt] #254545 15/08/15 11:05 AM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
It does work, but practically speaking nobody does/need that, I think you just made up a very weird case scenario where it could be used INSTEAD OF the com object, which could still be used and I'm certain would be prefered because it's more predictable, if you are making a script for it, you want it to be predictable, otherwise, you use explorer to delete a folder.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Delete folder with files [Re: Wims] #254671 24/08/15 09:29 AM
Joined: Dec 2002
Posts: 4,733
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,733
The script below is designed to mimic the way /rmdir behaves but will delete the folder and its contents:

Code:
rmdirex {
  if ($len($1-) == 0) {
    echo 2 -e * /rmdirex: insufficient parameters
    return
  }

  var %dir = $mircdir $+ $1-
  if (!$isdir(%dir)) return

  window -sh @rmdirex
  aline @rmdirex %dir
  noop $findfile(%dir, *.*, 0, aline @rmdirex $1-)
  noop $finddir(%dir, *.*, 0, aline @rmdirex $1-)

  var %n = $line(@rmdirex, 0)
  while (%n > 0) {
    var %fn = $line(@rmdirex, %n)
    if ($isdir(%fn)) .rmdir %fn
    else .remove -b %fn
    dec %n
  }

  window -c @rmdirex
  return

  :error
  reseterror
  window -c @rmdirex
  echo 2 -e * /rmdirex: unable to remove ' $+ %dir $+ '
}

By using /window -s to sort the list, files and folders are listed after their containing folders, so all the script needs to do is go backwards through the list. Note that it uses /remove -b to move deleted files to the recycle bin.

Re: Delete folder with files [Re: Khaled] #254673 24/08/15 12:52 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
Nice script!
Though, like I said, it's doable with a procedural script, but now you're using a while loop to remove everything, on huge folder, this would be much slower than the COM object script.
What do you think about adding a new 'f' switch to /rmdir to include this feature, removing all the files and subfolders from the folder?


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net