Action Part: Target and Backup Files
Near the bottom of the Action panel, you can select how PowerGREP should save, modify or copy files while you execute the action. To run an action without modifying any files at all, simply use the Preview button. Previewing an action never modifies any files or do anything else you might regret.
Target Files
Target File Creation
The available target types depend on the kind of action you have prepared. Seven target types are available for “search”, “collect data”, and “file or folder name collect” actions:
- Do not save results to file: Display the results on the Results panel in PowerGREP only.
- Save results into a single file: Save the text collected from all the files into a single new file.
- Copy results to the clipboard: Copy the text collected from all the files to the clipboard.
- Store results in the editor: Store the text collected from all the files in an unsaved file on the Editor panel.
- Modify original files: Save the text collected in each file to the file, overwriting the original file. The end result is a search and replace that deletes unmatched parts of the file.
- Save one file for each searched file: Create a new file for each file that has one or more search matches. Save the text collected from the file into the new file.
- Path placeholders: Use path placeholders to dynamically build a full target path for each file searched through. If the placeholders result in the same target path for multiple files searched through, the text collected from all those files will be combined into the target file.
For a “list files” or file or folder name search action, nine target types are available:
- Do not save results to file: Display the results on the Results panel in PowerGREP only.
- Save list of matched files to file: Save the list of file names into a single new file.
- Copy list of matched files to clipboard: Copy the list of file names to the clipboard.
- Store list of matched files in the editor: Store the list of file names in an unsaved file on the Editor panel.
- Copy matched files: If a file has one or more search matches, make a copy of it. Copy all included files if there is no seach term. You can use the target file destination type to compress or decompress files, leaving the originals.
- Move matched files: If a file has one or more search matches, move it into a different folder. Move all included files if there is no seach term. You can use the target file destination type to compress or decompress files, removing the originals.
- Convert matched files to text: Convert files in proprietary file formats that have search matches into plain text files with a .txt extension and using a certain text encoding and/or line break style. Change the text encoding and/or line break styles of plain text files with search matches (overwriting the original file).
- Convert copies of matched files to text: Create copies of all files with search matches. Copy the plain text conversion of files in proprietary formats. Change the text encoding and/or line break style of all copies.
- Delete matched files: If a file has one or more search matches, permanently delete it.
If you set “what to search through” for a “file and folder name search” action to search through folder names, then you get a different list of nine target types:
- Do not save results to file: Display the results on the Results panel in PowerGREP only.
- Save list of matched folders to file: Save the list of folder names into a single new file.
- Copy list of matched folders to clipboard: Copy the list of folder names to the clipboard.
- Store list of matched folders in the editor: Store the list of folder names in an unsaved file on the Editor panel.
- Copy matched folders: If a folder’s name or path has one or more search matches, make a copy of that folder and all its contents. Copy all included folders if there is no seach term. Copy folders with all their contents, including hidden files and folders. If the target folder already exists, move it to its backup location as a whole. If backups are disabled, delete the existing target folder before copying the matched folder. Do not search through the names of folders inside copied folders to avoid making copies of copies.
- Move matched folders: If a folder’s name or path has one or more search matches, move that folder and all its contents into another folder. Move all included folders if there is no seach term. Move folders with all their contents, including hidden files and folders. If the target folder already exists, move it to its backup location as a whole. If backups are disabled, delete the existing target folder before moving the matched folder. Also search through the names of folders inside moved folders. If they match, move them on their own after they were moved along with their parent folder.
- Copy contents of matched folders: If a folder’s name or path has one or more search matches, make a copy of that folder and all its contents. Copy all included folders if there is no seach term. Individually copy the files inside the matched folder, and inside all its subfolders. Skip hidden files and folders. If the target folder already exists, merge the contents of the matched folder with the contents of the target folder. If this causes files to be overwritten, back up those files individually. Do not search through the names of folders inside copied folders to avoid making copies of copies.
- Move contents of matched folders: If a folder’s name or path has one or more search matches, move that folder and all its contents into another folder. Move all included folders if there is no seach term. Individually move the files inside the matched folder, and inside all its subfolders. If the folder contains hidden files and folders, skip those and leave the original folder behind with those. If the target folder already exists, merge the contents of the matched folder with the contents of the target folder. If this causes files to be overwritten, back up those files individually. Also search through the names of folders inside moved folders. If they match, move them on their own after they were moved along with their parent folder.
- Delete matched folders: If a folder’s name or path has one or more search matches, delete the folder and all its contents. Delete all included folders if there is no seach term.
A “search and replace” or “search and delete” action offers three target types:
- Modify original files: Make the replacements in the files searched through.
- Copy only modified files: If a file has one or more search matches, make a copy of it and modify the copy.
- Copy all searched files: Make a copy of all files searched through, and modify the copy if the file has one or more search matches.
The “merge files” action type offers three choices:
- Merge into a single file: Merge all the files into a single new file.
- Merge based on search matches: Search through the files to be merged and determine the target file to merge each file into based on the search match in each file. You can specify the target in the main action, like you would specify the replacement text in a search-and-replace action.
- Path placeholders: Use path placeholders to dynamically build a full target file to merge each file into.
When you set the action type to “rename files or folders” you can choose to rename or copy the files or folders to their new names. Because there are different implications to changing a file’s name, a file’s path, a folder’s name, or a folder’s path, the available target types depend on the “what to rename” setting at the top of the action panel. When it is set to “file names only”, you get these target types:
- Rename files: Rename each file to the name created by searching-and-replacing through the file’s name.
- Copy files: Copy each file to the name created by searching-and-replacing through the file’s name.
When renaming relative or full paths to files, the target types change slightly to refect that changes to a file’s path can move the file into a new folder:
- Rename or move files: Rename or move each file to the path created by searching-and-replacing through the file’s path. Folders in the new path are created as needed.
- Copy files: Copy each file to the path created by searching-and-replacing through the file’s path. Folders in the new path are created as needed.
You can compress or decompress individual files by adding or removing extensions of individual compression formats like .gz or .xz.
When moving or copying folders, there are two ways of dealing with the files in those folders. The folders can be copied or moved entirely, or the contents of those folders can be copied or moved as individual files.
- Rename or move folders: Rename or move each folder and its contents to the path created by searching-and-replacing through the folder’s path. Renamed and moved folders retain all their contents, including hidden files and folders. If the target folder already exists, move it to its backup location as a whole. If backups are disabled, delete the existing target folder before renaming or moving the matched folder. Also rename or move folders inside renamed folders.
- Copy folders: Copy each folder to the path created by searching-and-replacing through the folder’s path. Copy folders with all their contents, including hidden files and folders. If the target folder already exists, move it to its backup location as a whole. If backups are disabled, delete the existing target folder before copying the matched folder. Do not search-and-replace through the paths of folders inside copied folders to avoid making copies of copies.
- Move contents of folders: Search-and-replace through the paths of folders to determine the target folders to move their contents to. Individually move the files inside the matched folder, and inside all its subfolders. If the folder contains hidden files and folders, skip those and leave the original folder behind with those. If the target folder already exists, merge the contents of the matched folder with the contents of the target folder. If this causes files to be overwritten, back up those files individually. Also search-and-replace through the paths of folders inside moved folders. Move the contents of those folders on their own after they were moved along with their parent folder.
- Copy contents of folders: Search-and-replace through the paths of folders to determine the target folders to move their contents to. Individually copy the files inside the matched folder, and inside all its subfolders. Skip hidden files and folders. If the target folder already exists, merge the contents of the matched folder with the contents of the target folder. If this causes files to be overwritten, back up those files individually. Do not search-and-replace through the paths of folders inside copied folders to avoid making copies of copies.
You can compress folders by adding an extension of an archive formats like .zip or .7z to their name. You can decompress archives by removing those extensions from their names.
Target File Destination Type
Select the type of place you want the target files to be created. Except when using path placeholders, target files will have the same name as the original files.
- Single folder: Place all files into a single folder.
- Folder tree: Place all files into a specific folder. If you marked a folder to also include its subfolders, those subfolders will be recreated under the target folder.
- Compressed archive: Place all files into a single .zip or .7z archive. If you marked a folder to also include its subfolders, those subfolders will be recreated inside the archive. If the archive already exists, the files will be added to it. If the archive already contains a file with the same name, a backup copy of that file is created.
- Numbered archive: Similar to the "compressed archive" option, except that if the archive already exists, a new archive will be created with a number added to its name.
- Path placeholders: Use path placeholders to dynamically build a full target path for each file searched through. You should take care to use a unique target path for each file. Otherwise the targets will overwrite each other.
Target File Location
Specify a target location of the type selected in the target file destination type list. Click the (...) button to interactively select or build the target location.
Target File Text Encoding
Select the Unicode encoding or the Windows code page the target file(s) should use. Choose "same as original file" if unsure.
Target File Line Break Style
Select the character sequence to be used to separate lines in the target file. Choose "same as original file" if unsure.
Order of Matches from Different Files
When collecting data into a single file without both grouping identical matches and grouping results for all files, this option determines in which order the collected matches are saved into that file.
- No particular order: Collect items as search matches are found. This is the fastest option. Since PowerGREP searches multiple files concurrently, text collected from one file may be mixed with text collected from other files. If you set "between collected text" to put text between matches from different files, or you specify source file headers and footers, PowerGREP will keep each file's matches together even if you specify "no particular order". This makes sure the headers, footers, and text between files appear logically.
- Keep each file's matches together: Collect matches as each file is processed. Text collected from one file will never be mixed with text collected from any other files. Since PowerGREP searches multiple files and drives concurrently, the blocks of text collected from different files are not ordered in relation to those files.
- Sort files alphanumerically: A..Z, 0..9: Keep each file's matches together. Create the target file after all files have been processed, collecting text in alphanumeric order of the files.
- Sort files alphanumerically: Z..A, 9..0: The previous option, in reverse.
- Sort files by increasing totals: Keep each file's matches together. Create the target file after all files have been processed, starting with the file with the fewest search matches until the file with the most search matches.
- Sort files by decreasing totals: The previous option, in reverse.
- Newest file to oldest file: Keep each file's matches together. Create the target file after all files have been processed, starting with the file that was modified the shortest time ago until the file that was modified the longest time ago.
- Oldest file to newest file: The previous option, in reverse.
Backup Files
Whenever you specify a target type that may cause files to be overwritten, you should specify how PowerGREP should create backup copies of files that are overwritten. While you can tell PowerGREP not to create backup copies at all, this is not recommended. PowerGREP needs the backup copies to be able to undo the action in the Undo History. If no backup files are created, PowerGREP will not add the action to the Undo History at all.
Backup File Naming Style
When a target file already exists, PowerGREP can make a backup copy of the file before overwriting it. The name of the backup copy is based on the name of the target file.
- No backups: Do not create backups at all. You will not be able to undo the action if it overwrites files.
- Single *.bak: Append a ".bak" extension. The backup of FileName.ext is FileName.ext.bak. If the backup file already exists, it will be overwritten. This option gives backup files a unique file type in Windows Explorer.
- Single *.~*: Insert a tilde into the file's extension. The backup of FileName.ext is FileName.~ext. If the backup file already exists, it will be overwritten.
- Multi .bak, .bak2, ...: Append a ".bak" extension. If the backup file already exists, append a number to the extension to make the file name unique.
- Multi "Backup N of ...": Prepend "Backup 1 of " to the file's name. The backup of FileName.ext is "Backup 1 of FileName.ext". If the file already exists, the number is incremented to make the file name unique. This option preserves the extension, making it easy to open backup files in the original application.
- Same file name: Use the same file name for the backup as the original. This option requires you to place backup files into a separate folder or .zip archive. If the backup file already exists, it will be overwritten.
- Path placeholders: Use path placeholders to dynamically build a full backup path for each file that needs to be backed up.
- Hidden history: Store backup files in a hidden __history subfolder of each folder in which files are overwritten. This option makes sure backup files don't clutter up your folders.
Backup File Destination Type
Select the type of place you want the backup files to be created.
- Same folder as original: Place the backup file in the same folder as the file it is a backup of.
- Subfolder of original folder: Place the backup file in a subfolder of the folder that holds the file that it is a backup of.
- Single folder: Place all backup files into a single folder.
- Folder tree: Place all backup files into a specific folder. If you marked a folder in the file selection to also include its subfolders, those subfolders will be recreated under the target folder.
- Compressed archive: Place all backup files into a .zip or .7z archive. If you marked a folder to also include its subfolders, those subfolders will be recreated inside the .zip archive. If the archive already exists, the files will be added to it.
- Numbered archive: Similar to the "compressed archive" option, except that if the archive already exists, a new archive will be created with a number added to its name.
Backup File Location
Specify a target location of the type selected in the backup file destination type list. Click the (...) button to interactively select or build the backup location.