Delete files from directory if filename contains a certain word

To expand on Henk’s answer, you need: string rootFolderPath = @”C:\\SomeFolder\\AnotherFolder\\FolderCOntainingThingsToDelete”; string filesToDelete = @”*DeleteMe*.doc”; // Only delete DOC files containing “DeleteMe” in their filenames string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete); foreach(string file in fileList) { System.Diagnostics.Debug.WriteLine(file + “will be deleted”); // System.IO.File.Delete(file); } BE VERY CAREFUL! Note that I’ve commented out the delete command. Run … Read more

Check if extended property description already exists before adding

This first script checks if the extended property describing the table exists: IF NOT EXISTS (SELECT NULL FROM SYS.EXTENDED_PROPERTIES WHERE [major_id] = OBJECT_ID(‘Table_Name’) AND [name] = N’MS_Description’ AND [minor_id] = 0) EXECUTE sp_addextendedproperty @name = N’MS_Description’, @value = N’This table is responsible for holding information.’, @level0type = N’SCHEMA’, @level0name = N’dbo’, @level1type = N’TABLE’, @level1name … Read more