Author Topic: delete certain files in multiple folders  (Read 22631 times)

karthik

  • Active Member
  • ***
  • Posts: 56
    • View Profile
delete certain files in multiple folders
« on: March 17, 2014, 17:18:26 »
Hello,

I have a main directory, which has say 20 folders. Each folder has a certain set of files (*.txt,*.dat,*.xls, etc). Out of these 20 folders, I want to keep only *.txt in 15 of these folders (which I select) and delete the rest of the files in the 15 folders. The remaining folders, I don't want to be touched.

Currently, I just select the 15 folders, move it to a temp directory (and while moving give options so that the move command moves only *.txt) and the delete the source folders and then move the folders from the temp directory to my working directory.

Is there a easier way to do this in MC?

Thanks.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4450
    • View Profile
    • Multi Commander
Re: delete certain files in multiple folders
« Reply #1 on: March 17, 2014, 19:22:23 »
Delete using filter is disabled since it is not fixed yet.. But you can use search..

Start Search panel
search for everything in the location you want to delete
Then right click on a .txt file an select "exclude .txt" and they are removed from search result.
sort by ext. (so that files and folders are not mixed.)
then select all files. (do not select the folders)
press delete to delete all the selected files. (what should be all files except the .txt file that you excluded)

karthik

  • Active Member
  • ***
  • Posts: 56
    • View Profile
Re: delete certain files in multiple folders
« Reply #2 on: March 18, 2014, 03:19:18 »
Thanks, Mathias.

The way you have mentioned, "search for everything in the location you want to delete" - the problem is the location has 20 folders and I want to search only in 15 folders. The search panel doesn't allow me to do search in multiple folders.

Thanks.


karthik

  • Active Member
  • ***
  • Posts: 56
    • View Profile
Re: delete certain files in multiple folders
« Reply #3 on: March 18, 2014, 03:20:07 »
Is there a way to do a scripting. If yes, just give some pointers and I will attempt to do it.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4450
    • View Profile
    • Multi Commander
Re: delete certain files in multiple folders
« Reply #4 on: March 18, 2014, 06:44:25 »
The way you have mentioned, "search for everything in the location you want to delete" - the problem is the location has 20 folders and I want to search only in 15 folders. The search panel doesn't allow me to do search in multiple folders.
You can enter multiple paths and separate then with ";" eg  "C:\MyFolder1;C:\MyFolder2;C:\MyFolder3"
Or you can exclude folders in the "Exclude filter box"

Is there a way to do a scripting. If yes, just give some pointers and I will attempt to do it.

There is some scripting.. But not sure if it helps
http://multicommander.com/docs/customcommands_list#mc.filesearch.search

or more advanced, scan the filesystem and find the file you want to delete your self
http://multicommander.com/docs/multiscript/functions/filesystem

karthik

  • Active Member
  • ***
  • Posts: 56
    • View Profile
Re: delete certain files in multiple folders
« Reply #5 on: March 18, 2014, 07:05:40 »
Thanks, Mathias.

This gives me some idea. How can I concatenate two strings in multi-script.

Thanks.

karthik

  • Active Member
  • ***
  • Posts: 56
    • View Profile
Re: delete certain files in multiple folders
« Reply #6 on: March 18, 2014, 07:21:36 »
I figured that '+' concatenates two strings

I tried to write a script that can give me the path of the 15 folders separated by a ';' and here it is:

@var $arr = GetSelectedPaths();
@var $len = arrayCount($arr)
@var $n
@var $str = $arr[0]
for( $n = 1; $n <= $len-1; $n++)
{
   $str = $str + ";" + $arr[$n]
}
SetClipboardText($str)

But I find that the string str does not get updated. Can you let me know what am missing?

Also, can I use this string "str" as the filesearch "look in" box automatically?

Thanks

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4450
    • View Profile
    • Multi Commander
Re: delete certain files in multiple folders
« Reply #7 on: March 18, 2014, 07:28:59 »
Not sure.. but I thing it does not like it when you are reading and writing to the same variable..
Code: [Select]
$str = $str + ";" + $arr[$n]
Change that to
Code: [Select]
$str += ";" + $arr[$n];
So that it will then be.
Code: [Select]
@var $arr = GetSelectedPaths();
@var $len = arrayCount($arr)
@var $n
@var $str = $arr[0]
@var $new;
for( $n = 1; $n <= $len-1; $n++)
{
   $str += ";" + $arr[$n];
}
SetClipboardText($str);

karthik

  • Active Member
  • ***
  • Posts: 56
    • View Profile
Re: delete certain files in multiple folders
« Reply #8 on: March 18, 2014, 07:35:46 »
Thanks, Mathias.

The following code works fine now. Am able to get this text to the filesearch window as well.

@var $arr = GetSelectedPaths();
@var $len = arrayCount($arr)
@var $n
@var $str = $arr[0]
@var $new;
for( $n = 1; $n <= $len-1; $n++)
{
   $str += ";" + $arr[$n];
}
MC.FileSearch.Search SEARCHIN="{$str}" SEARCHFOR="*.*" EXCLUDE=".backup" AUTOSTART

Now I have '.backup' in exclude. Can I get that as argument.

Ideally, I want to type
del_files '.backup' and it should execute the above script (del_files should be an alias to execute the script), and use the argument '.backup' in the EXCLUDE field of the MC.Filesearch line and give me the result.

Can I do that?

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4450
    • View Profile
    • Multi Commander
Re: delete certain files in multiple folders
« Reply #9 on: March 18, 2014, 10:13:55 »
$argcount, $arg[...] are hardcoded variables that exits if script is run with parameters.

Code: [Select]
@var $exclude = "";
@var $n;
for( $n = 0; $n < $argcount; $n++ )
{
  if( StrLen( $exclude ) > 0)
  {
    $exclude += " "
  }
  $exclude += $arg($n);
}

EXCLUDE list is space separate, so the above part adds a space between them.
Since the command line field also separate by space. you need to quote paths when entering them, if they have space in them.. the space character are kept in $arg[..] so no need to readd quotes..

« Last Edit: March 18, 2014, 10:15:48 by Mathias (Author) »