掌上百科 - PDAWIKI

 找回密码
 免费注册

QQ登录

只需一步,快速开始

查看: 333|回复: 0

[教程] powergrep 005

[复制链接]

该用户从未签到

发表于 2017-11-20 19:25:17 | 显示全部楼层 |阅读模式
本帖最后由 zhu1234 于 2017-11-20 19:46 编辑 / h: Y7 a0 b9 I9 \$ R" x

) U, C. z2 R1 Y; P' `: V! nRename Files Based on HTML Title Tags* q+ V+ K1 ^# h0 n1 g4 R

# ]. G7 q4 k+ q3 `6 B! ?+ v- lThe "rename files or folders" action type enables you to rename files by searching and replacing through their file names or paths. With the "filter files" feature you can first run a search through the contents of each file and then use (part of) the search match in the search-and-replace through the file's name. This way you can extract text from the file's contents and insert it into the file's name.
) k, V- o( m, h. g) E% V! p0 s
3 n4 r! `* d! U, ^0 n1 Q* @- J8 zAs an example, we'll rename a bunch of HTML files. The new name of each file will be whatever is specified in the <TITLE> tag inside the file. If a file does not have a <TITLE> tag, we use the contents of the <H1> tag instead. If a file has neither tag, it is not renamed.
7 K0 ]4 B4 ^3 S6 P% h
- v) L2 y5 ~' @& [Rename Files Based on HTML Title Tags( R( j" z' g2 j

6 o# l9 h: B) Y1 `% {Select the HTML files you want to rename in the File Selector.
) O; m: N* E0 u, N" cMake sure the file format configuration searches through the raw (unconverted) contents of HTML files. The predefined "None" configuration is one that does this.
2 e; g7 k3 L% h, |. fStart with a fresh action.) @, |) M6 X' r2 y9 u
Set the action type to "rename files or folders".
9 X, N  i, Y! ~+ x/ \( q' {% gLeave "what to rename" set to "file name only". Our search-and-replace should only change the file's name.
/ [; o# b  u" ~Set "filter files" to "require all search terms to match". Leave the search type as "regular expression".
: W2 }3 S' D1 D( n9 D" l" y1 H1 ?Enter the regular expression <(TITLE|H1)[^<>]*>(?'title'[^<>]+)</\1> in the Search box in the "filter files" part of the action. This regex matches the opening and closing <TITLE> or <H1> tags (whichever pair comes first) and any text between them. The text between them is captured into the named capturing group "title".! P) ?- M7 `$ a, M& ~% p
Enter the regular expression ^.*\. in the Search box in the main part of the action. This regex matches everything up to and including the last dot in the file's name.' Z0 s9 i( P' P& U; z' {; B
Enter the replacement text ${title}. to replace the file's name with the contents of the tag matched by the "filter files" regex. The replacement also puts back the dot that delimits the file's extension. The extension is not matched by the regex and thus remains unchanged.% Y) v& N) v0 ]$ R$ U
Tick the extra processing checkbox. An additional set of controls for entering search terms appears.
% ^! g- ~! U+ V* ^5 Q  G  V" wUse [\\/:*?"<>|] as the regular expression for extra processing. This regex matches any character that is not allowed in file names by the Microsoft Windows operating system.7 r" B/ r" P3 P; h; f' n
Leave the extra processing replacement blank so invalid characters are deleted.) g) b; \3 l- R: c' |9 D( j  d
Set the backup file options as you like them., z5 f- Q5 h" x% e9 U: z
Click the Preview button to run a test.) S0 o% B& E- X  P  l  y
If all looks well, click the Rename button to actually rename the files.' X2 l9 W* m# p1 B- B0 C

- |4 r0 \0 G; k3 w' s3 m/ ~0 Y3 x4 B  Y; mShould a file not have a <TITLE> or <H1> tag, then it is filtered out and not renamed. If a file has both a <TITLE> and <H1> tag, or multiple occurrences of the same tag, then only the first tag is used. Once all the regular expressions in "filter files" have found a match, PowerGREP considers the file to meet the filtering requirement. It won't look for any further matches for the filtering regex.8 G6 ?# h, j4 i
+ |* H: R8 s2 }, N% A
This action is available in the PowerGREP5.pgl library as "Rename files based on HTML title tags".
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

小黑屋|手机版|Archiver|PDAWIKI |网站地图

GMT+8, 2024-4-27 04:43 , Processed in 0.032707 second(s), 9 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表