Summary: How to import plain text files into PmWiki Version: Prerequisites: Status: Maintainer: Categories: Administration
I would like to import a load of plain text files into my pmwiki. (There's almost no markup on them so they don't need converting, and there's no history.)
Copy the text below and paste it as a clip into a NoteTab library. (choose a clipbook to store this, click on its button to make it visible, right-click the clip above which you want to add this one, select Add from Clipboard, give it a name - I call it wikifiles)
What it does:
Just in case that's not obvious from the code:
e.g. if the Group specified is Projects, a file named "first look.txt" will become Projects.FirstLook.
; NoteTab clip for transforming a set of text files into PmWiki pages ; by Radu Luchian (email@example.com) ; works only on Windoze... someone should write a perl script or something... ;) ; get NoteTab from www.notetab.com ; (this clip should work with the free version, but please consider buying their Standard or Pro) ; ^!SetWizardLabel "Enter values for wiki page attributes" ^!Set %CR%=^$RemoveTokens("^P")$ ^!Set %tG%=^?[Target group=Main|Site|_Projects] ^!Set %nA%=^?[Author name=Radu] ^!Set %tN%=^?[Time stamp=1124278219] ^!Set %fT%=^?[File types to use=all^=*.txt;*.csv|_txt^=*.txt|csv^=*.csv] ^!Set %ff%=^?[(T=O;F="Text files|*.txt;*.csv")&Pick any file in the target folder] ^!Set %fName%=^$GetFileFirst(^$GetPath(^%ff%)$;"^%fT%";^?[Order=_ascending^=|descending^=REV]^?[Order of processing=UNSORTED|_NAME|TYPE|DATE|SIZE])$ :Loop ^!IfTrue ^$IsEmpty(^%fName%)$ END ^!Set %nFN%=^$GetPath(^%fName%)$wiki.d\^%tG%.^$StrReplace(" ";"";^$StrCapitalize(^$StrDeleteRight(^$GetFileName(^%fName%)$;4)$)$;False;False)$ ^!TextToFile ^%nFN% version=pmwiki-2.0.beta54^%CR% ^!AppendToFile ^%nFN% newline= ^%CR% ^!AppendToFile ^%nFN% time=^%tN%^%CR% ^!AppendToFile ^%nFN% text=^$StrReplace("^P";" ";^$StrFixLines(^$GetFileText(^%fName%)$)$;False;False)$^%CR% ^!AppendToFile ^%nFN% author=^%nA%^%CR% ^!Set %fName%=^$GetFileNext$ ^!Goto Loop
Notes and Comments
This should work on any pmwiki version, with minor changes to the script. Just take a look at the files you have in wiki.d and make the script do what you want. If you don't want to sign the newly created pages with an author, just remove the two lines (declaring the variable and writing it to the file)
It's a good idea to edit the clip after you paste it, and set your own preferences: Author name, Groups you have, etc. Values are separated by "|". The default value in a pop-up is prefixed with an underscore "_"
The Script is intended to be run from the command line and pulls all the text files (.txt) from a given directory and converts them to the proper format for PmWiki pages. In addition it renames the files to the PmWiki naming convention.
A quick test run on Windows output the following:
C:\WINDOWS\Desktop>c:\php\php.exe -f ImportText.php c:\windows\desktop\test1\ c:\windows\desktop\test2\ test Opening Directory: c:\windows\desktop\test1\ Skipping . Skipping .. Reading: L1018.txt Writing: c:\windows\desktop\test2\Test.L1018 Reading: L1012.txt Writing: c:\windows\desktop\test2\Test.L1012 Reading: L101.txt Writing: c:\windows\desktop\test2\Test.L101 Reading: L1028.txt Writing: c:\windows\desktop\test2\Test.L1028 Reading: L1034.txt Writing: c:\windows\desktop\test2\Test.L1034 Conversion complete C:\WINDOWS\Desktop>