这是一个go程序为html文件批量增加上下页

This commit is contained in:
leo
2018-05-25 22:21:50 +08:00
parent a7e12d60f7
commit 8465c1fdc7
2 changed files with 288 additions and 0 deletions

188
de1/.idea/workspace.xml generated Normal file
View File

@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="b80b2fcf-256f-4c43-8992-60f6150d30c7" name="Default" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf />
</component>
<component name="GOROOT" path="/usr/lib/go-1.9" />
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/a_herf.go" />
</list>
</option>
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsGulpfileManager">
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="y" value="30" />
<option name="width" value="1366" />
<option name="height" value="738" />
</component>
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
<manualOrder />
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="de1" type="b2602c69:ProjectViewProjectNode" />
<item name="de1" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scratches" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="go.sdk.automatically.set" value="true" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager">
<configuration default="true" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="de1" />
<working_directory value="$PROJECT_DIR$/" />
<go_parameters value="-i" />
<kind value="FILE" />
<filePath value="$PROJECT_DIR$/" />
<directory value="$PROJECT_DIR$/" />
</configuration>
<configuration name="go build a_herf.go" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
<module name="de1" />
<working_directory value="$PROJECT_DIR$/" />
<go_parameters value="-i" />
<kind value="FILE" />
<filePath value="$PROJECT_DIR$/a_herf.go" />
<directory value="$PROJECT_DIR$/" />
</configuration>
<configuration default="true" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="de1" />
<working_directory value="$PROJECT_DIR$/" />
<go_parameters value="-i" />
<framework value="gotest" />
<kind value="DIRECTORY" />
</configuration>
<recent_temporary>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="Go Build.go build a_herf.go" />
</list>
</recent_temporary>
</component>
<component name="ShelveChangesManager" show_recycled="false">
<option name="remove_strategy" value="false" />
</component>
<component name="ToolWindowManager">
<frame x="0" y="30" width="1366" height="738" extended-state="6" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.27954546" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32885906" sideWeight="0.50297177" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.39967373" sideWeight="0.49702823" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32952693" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.39937106" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager />
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file:///usr/lib/go-1.9/src/os/file_unix.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="106">
<caret line="146" column="46" lean-forward="false" selection-start-line="146" selection-start-column="46" selection-end-line="146" selection-end-column="46" />
<folding />
</state>
</provider>
</entry>
<entry file="file:///usr/lib/go-1.9/src/os/types.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="124">
<caret line="44" column="47" lean-forward="false" selection-start-line="44" selection-start-column="30" selection-end-line="44" selection-end-column="50" />
<folding />
</state>
</provider>
</entry>
<entry file="file:///usr/lib/go-1.9/src/syscall/zerrors_linux_amd64.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-15792">
<caret line="658" column="12" lean-forward="false" selection-start-line="658" selection-start-column="12" selection-end-line="658" selection-end-column="12" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/a_herf.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-780">
<caret line="45" column="42" lean-forward="true" selection-start-line="45" selection-start-column="42" selection-end-line="45" selection-end-column="42" />
<folding />
</state>
</provider>
</entry>
<entry file="file:///usr/lib/go-1.9/src/os/file.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="610">
<caret line="64" column="9" lean-forward="false" selection-start-line="64" selection-start-column="9" selection-end-line="64" selection-end-column="9" />
<folding />
</state>
</provider>
</entry>
</component>
</project>

100
zh/a_herf.go Normal file
View File

@@ -0,0 +1,100 @@
package main
import(
"fmt"
"log"
"os"
"path/filepath"
"sort"
)
func dir()([]string,error) {
path, err := os.Getwd()
if err != nil {
fmt.Println("err is:", err)
}
log.Println(path)
path =path +"/*.html"
fmt.Println(path)
files,err := filepath.Glob(path)
var s =make([]string,len(files))
var head uint8 =0
for _,k :=range files {
filename := filepath.Base(k)
head=filename[0]
if (head < 52) {
s = append(s, filename)
fmt.Println(filename)
}
}
sort.Strings(s)
return s,err
}
func htmlfile(filename string,next_path string,last_path string)(error){
file,err:= os.OpenFile("./"+filename,os.O_RDWR,0666)
if err !=nil{
fmt.Println("something is err :",err)
}
defer file.Close()
var add_string1 string = "\n<a href=\"./"+next_path+"\">下一页</a>\n"
var add_string2 string = "\n<a href=\"./"+last_path+"\">下一页</a>\n"
file.Seek(1,2)
_,err=file.WriteString(add_string1)
_,err=file.WriteString(add_string2)
file.Seek(0,0)
if(err!=nil){
fmt.Println("err:",err)
}
var f =make([]byte,50000)
_,err=file.Read(f)
if(err!=nil){
fmt.Println("error:",err)
}
//fmt.Println(string(f))
return err
}
func nextandlast(filenames []string,index int )(filename string,next_path string,last_path string){
fmt.Println(index," ---",index+1)
filename = filenames[index]
if(0<index && index<len(filenames)-1) {
next_path = filenames[index+1]
last_path = filenames[index-1]
}else if(index==0){
next_path =filenames[index+1]
last_path = filenames[len(filenames)-1]
}else if(index==len(filenames)){
next_path =filenames[0]
last_path =filenames[index-1]
}else{
return
}
return filename,next_path,last_path
}
func main(){
files,err:=dir()
if(err!=nil){
fmt.Println(err)
}
//fmt.Println(files)
// var tmp string ="\0"
for i, v :=range files{
if(v!=""){
fmt.Println(v)
filename,next_path,last_path :=nextandlast(files,i)
err:=htmlfile(filename,next_path,last_path)
if(err!=nil){
fmt.Println("err=",err)
}else if(v==""){
continue
}
}
}
log.Println("end")
return
}