is it possible to delete files / folders using speicific part of the file/folder name

Discussion in 'Windows 10' started by RanCorX2, Jan 2, 2017.

  1. RanCorX2

    RanCorX2 MDL Addicted

    Jul 19, 2009
    891
    458
    30
    as title says, it it possible delete a whole load of files/folders that have different names using just parts of the each file/folder name?

    like a bunch of language files with same begining name but a different end name for each one?


    like if i wanted to remove all files/folders with "_ar-sa_" in winsxs?

    amd64_microsoft.windows.c..-controls.resources_6595b64144ccf1df_5.82.14393.0_ar-sa_c2bd6350b3617a2c

    just working on a winsxs cleapup project but need an easier way to remove the files/folders when a new version is installled.

    does this make sense and is it possible?
     
  2. RanCorX2

    RanCorX2 MDL Addicted

    Jul 19, 2009
    891
    458
    30
    aww thanks man, this will save me hours!
     
  3. pisthai

    pisthai Imperfect Human

    Jul 29, 2009
    6,869
    2,032
    210
    Normally the 'Wildcard' sign is the * (Star) and not _ (underline)! Maybe that could work!

    Just take a lot of Caution if you try that, it's totally on your own risk!!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. RanCorX2

    RanCorX2 MDL Addicted

    Jul 19, 2009
    891
    458
    30
    #4 RanCorX2, Jan 2, 2017
    Last edited: Jan 2, 2017
    (OP)
    ok, will test before trying for real :)

    tried it but it didn't work

    "The filename, directory name, or volume label syntax is incorrect."

    any idea why?

    anyone got a working solution?
     
  5. RanCorX2

    RanCorX2 MDL Addicted

    Jul 19, 2009
    891
    458
    30
    #5 RanCorX2, Jan 2, 2017
    Last edited: Jan 2, 2017
    (OP)
    for /f "tokens=* delims= " %a in ('dir/b/ad ^| find "_ar-sa_"') do (rd /s /q %a)

    is working but doesn't work in a batch file, any ideas?

    nvm, all sorted now.
     
  6. LiteOS

    LiteOS MDL Expert

    Mar 7, 2014
    1,545
    654
    60
    powershell
    dir *mask* -re | rd -re -force
     
  7. abbodi1406

    abbodi1406 MDL KB0000001

    Feb 19, 2011
    8,212
    27,893
    270
    #7 abbodi1406, Jan 2, 2017
    Last edited by a moderator: Apr 20, 2017
    Sorry about previous post, i mixed dir with rd :D
    batch need double %% for variables
    Code:
    for /f "tokens=* delims=" %%a in ('dir /b /ad *ar-sa*') do (rd /s /q %%a)
     
  8. Katzenfreund

    Katzenfreund MDL Expert

    Jul 15, 2016
    1,372
    812
    60
    You first search for all files containing the common part or string of characters in their name. This will give you a list containing them. If that list seems OK to you, you then select them all and delete them simultaneously. This way you can also check what you are about to delete and exclude anything you want to keep.