Skip to main content
edited body
Source Link
Rudy Potter
  • 2.6k
  • 8
  • 20

Here is how I might approach it. I would make a list of directories to look in.

dirsToClean = {"C:\\Users\\rpotter\\Downloads", 
  "C:\\Users\\rpotter\\Documents", "C:\\Users\\rpotter\\Desktop"};

Then I would make a list of keywords.

keywords = {"test", "temp",".tmp"};

And add wildcards to either side of the keywords.

keywordsWC = "*" <> # <> "*" & /@ keywords
(*{"*test*", "*temp*", "*.tmp*"}*)

Now I can search for those files.

filesToDelete = FileNames[keywords2FileNames[keywordsWC, dirsdirsToClean, IgnoreCase -> True] (*Or False as desired*)

If everything looks good we can delete them.

FileDelete[filesToDelete]DeleteFile[filesToDelete]

But maybe before deleting them we move them to a folder so we can look through them first.

CreateDirectory["c:\\FilesToDelete"]
RenameFile[#, 
   FileNameJoin[{"c:\\FilesToDelete", 
     FileNameSplit[#][[-1]]}]] & /@ filesToDelete

And then just delete all the files in that directory.

Here is how I might approach it. I would make a list of directories to look in.

dirsToClean = {"C:\\Users\\rpotter\\Downloads", 
  "C:\\Users\\rpotter\\Documents", "C:\\Users\\rpotter\\Desktop"};

Then I would make a list of keywords.

keywords = {"test", "temp",".tmp"};

And add wildcards to either side of the keywords.

keywordsWC = "*" <> # <> "*" & /@ keywords
(*{"*test*", "*temp*", "*.tmp*"}*)

Now I can search for those files.

filesToDelete = FileNames[keywords2, dirs, IgnoreCase -> True] (*Or False as desired*)

If everything looks good we can delete them.

FileDelete[filesToDelete]

But maybe before deleting them we move them to a folder so we can look through them first.

CreateDirectory["c:\\FilesToDelete"]
RenameFile[#, 
   FileNameJoin[{"c:\\FilesToDelete", 
     FileNameSplit[#][[-1]]}]] & /@ filesToDelete

And then just delete all the files in that directory.

Here is how I might approach it. I would make a list of directories to look in.

dirsToClean = {"C:\\Users\\rpotter\\Downloads", 
  "C:\\Users\\rpotter\\Documents", "C:\\Users\\rpotter\\Desktop"};

Then I would make a list of keywords.

keywords = {"test", "temp",".tmp"};

And add wildcards to either side of the keywords.

keywordsWC = "*" <> # <> "*" & /@ keywords
(*{"*test*", "*temp*", "*.tmp*"}*)

Now I can search for those files.

filesToDelete = FileNames[keywordsWC, dirsToClean, IgnoreCase -> True] (*Or False as desired*)

If everything looks good we can delete them.

DeleteFile[filesToDelete]

But maybe before deleting them we move them to a folder so we can look through them first.

CreateDirectory["c:\\FilesToDelete"]
RenameFile[#, 
   FileNameJoin[{"c:\\FilesToDelete", 
     FileNameSplit[#][[-1]]}]] & /@ filesToDelete

And then just delete all the files in that directory.

edited body
Source Link
Rudy Potter
  • 2.6k
  • 8
  • 20

Here is how I might approach it. I would make a list of directories to look in.

dirsToClean = {"C:\\Users\\rpotter\\Downloads", 
  "C:\\Users\\rpotter\\Documents", "C:\\Users\\rpotter\\Desktop"};

Then I would make a list of keywords.

keywords = {"test", "temp",".tmp"};

And add wildcards to either side of the keywords.

keywordsWC = "*" <> # <> "*" & /@ keywords
(*{"*test*", "*temp*", "*.tmp*"}*)

Now I can search for those files.

filesToDelete = FileNames[keywords2, dirs, IgnoreCase -> True] (*Or False as desired*)

If everything looks good we can delete them.

FileDelete[filesToDelete]

But maybe before deleting them we move them to a folder so we can look through them first.

CreateDirectory["c:\\FilesToDelete"]
RenameFile[#, 
   FileNameJoin[{"c:\\FilesToDelete", 
     FileBaseName[#]FileNameSplit[#][[-1]]}]] & /@ filesToDelete

And then just delete all the files in that directory.

Here is how I might approach it. I would make a list of directories to look in.

dirsToClean = {"C:\\Users\\rpotter\\Downloads", 
  "C:\\Users\\rpotter\\Documents", "C:\\Users\\rpotter\\Desktop"};

Then I would make a list of keywords.

keywords = {"test", "temp",".tmp"};

And add wildcards to either side of the keywords.

keywordsWC = "*" <> # <> "*" & /@ keywords
(*{"*test*", "*temp*", "*.tmp*"}*)

Now I can search for those files.

filesToDelete = FileNames[keywords2, dirs, IgnoreCase -> True] (*Or False as desired*)

If everything looks good we can delete them.

FileDelete[filesToDelete]

But maybe before deleting them we move them to a folder so we can look through them first.

CreateDirectory["c:\\FilesToDelete"]
RenameFile[#, 
   FileNameJoin[{"c:\\FilesToDelete", 
     FileBaseName[#]}]] & /@ filesToDelete

And then just delete all the files in that directory.

Here is how I might approach it. I would make a list of directories to look in.

dirsToClean = {"C:\\Users\\rpotter\\Downloads", 
  "C:\\Users\\rpotter\\Documents", "C:\\Users\\rpotter\\Desktop"};

Then I would make a list of keywords.

keywords = {"test", "temp",".tmp"};

And add wildcards to either side of the keywords.

keywordsWC = "*" <> # <> "*" & /@ keywords
(*{"*test*", "*temp*", "*.tmp*"}*)

Now I can search for those files.

filesToDelete = FileNames[keywords2, dirs, IgnoreCase -> True] (*Or False as desired*)

If everything looks good we can delete them.

FileDelete[filesToDelete]

But maybe before deleting them we move them to a folder so we can look through them first.

CreateDirectory["c:\\FilesToDelete"]
RenameFile[#, 
   FileNameJoin[{"c:\\FilesToDelete", 
     FileNameSplit[#][[-1]]}]] & /@ filesToDelete

And then just delete all the files in that directory.

edited body
Source Link
Rudy Potter
  • 2.6k
  • 8
  • 20

Here is how I might approach it. I would make a list of directories to look in.

dirsToClean = {"C:\\Users\\rpotter\\Downloads", 
  "C:\\Users\\rpotter\\Documents", "C:\\Users\\rpotter\\Desktop"};

Then I would make a list of keywords.

keywords = {"test", "temp",".tmp"};

And add wildcards to either side of the keywords.

keywordsWC = "*" <> # <> "*" & /@ keywords
(*{"*test*", "*temp*", "*.tmp*"}*)

Now I can search for those files.

filesToDelete = FileNames[keywords2, dirs, IgnoreCase -> True] (*Or False as desired*)

If everything looks good we can delete them.

FileDelete[filesToDelete]

But maybe before deleting them we move them to a folder so we can look through them first.

CreateDirectory["c:\\FilesToDelete"]
RenameFile[#, 
   FileNameJoin[{"c:\\FilesToDelete", 
     FileBaseName[#]}]] & /@ filestodeletefilesToDelete

And then just delete all the files in that directory.

Here is how I might approach it. I would make a list of directories to look in.

dirsToClean = {"C:\\Users\\rpotter\\Downloads", 
  "C:\\Users\\rpotter\\Documents", "C:\\Users\\rpotter\\Desktop"};

Then I would make a list of keywords.

keywords = {"test", "temp",".tmp"};

And add wildcards to either side of the keywords.

keywordsWC = "*" <> # <> "*" & /@ keywords
(*{"*test*", "*temp*", "*.tmp*"}*)

Now I can search for those files.

filesToDelete = FileNames[keywords2, dirs, IgnoreCase -> True] (*Or False as desired*)

If everything looks good we can delete them.

FileDelete[filesToDelete]

But maybe before deleting them we move them to a folder so we can look through them first.

CreateDirectory["c:\\FilesToDelete"]
RenameFile[#, 
   FileNameJoin[{"c:\\FilesToDelete", 
     FileBaseName[#]}]] & /@ filestodelete

And then just delete all the files in that directory.

Here is how I might approach it. I would make a list of directories to look in.

dirsToClean = {"C:\\Users\\rpotter\\Downloads", 
  "C:\\Users\\rpotter\\Documents", "C:\\Users\\rpotter\\Desktop"};

Then I would make a list of keywords.

keywords = {"test", "temp",".tmp"};

And add wildcards to either side of the keywords.

keywordsWC = "*" <> # <> "*" & /@ keywords
(*{"*test*", "*temp*", "*.tmp*"}*)

Now I can search for those files.

filesToDelete = FileNames[keywords2, dirs, IgnoreCase -> True] (*Or False as desired*)

If everything looks good we can delete them.

FileDelete[filesToDelete]

But maybe before deleting them we move them to a folder so we can look through them first.

CreateDirectory["c:\\FilesToDelete"]
RenameFile[#, 
   FileNameJoin[{"c:\\FilesToDelete", 
     FileBaseName[#]}]] & /@ filesToDelete

And then just delete all the files in that directory.

deleted 10 characters in body
Source Link
Rudy Potter
  • 2.6k
  • 8
  • 20
Loading
Source Link
Rudy Potter
  • 2.6k
  • 8
  • 20
Loading