Summary: How to import plain text files into PmWiki Version: Prerequisites: Status: Maintainer: Categories: Administration Discussion: ImportText-Talk?


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.)


Radu: It could be done with a perl batch file, but at this time I'm stuck on Windoze and I'm using a nifty text editor called NoteTab (requires at least notetab v.4.82).

See below for a PHP script that does essentially the same thing. (Waylan)

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:

  • asks for a bunch of variables
  • takes a set of .txt or .csv files (feel free to add other extensions)
  • creates pmwiki pages in a subfoler called wiki.d under where the files are

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 (
; works only on Windoze... someone should write a perl script or something... ;)
; get NoteTab from
; (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])$
^!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=
^!AppendToFile ^%nFN% time=^%tN%^%CR%
^!AppendToFile ^%nFN% text=^$StrReplace("^P";"
^!AppendToFile ^%nFN% author=^%nA%^%CR%
^!Set %fName%=^$GetFileNext$
^!Goto Loop

Notes and Comments

  • This recipe was last tested on PmWiki version: 2.beta54
  • This recipe requires at least PmWiki version: ??

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 "_"

See Also

Here's a PHP script? I wrote that does this as well.

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.

  • Params: source/dir/ [ , destination/dir/ ] [ , groupname ] (optional params in [brackets])
  • Usage: php.exe -f ImportText.php /path/to/source/dir/ /path/to/destination/dir/ groupname
  • Notes:
    • each dir given as arg must contain an ending slash ('/')
    • When a group name is provided it is appended to begining of filename: (ie. file.txt becomes Groupname.File - note case change of first char for both group and file)
    • If no group name given, only file ext is striped (ie, file.txt becomes File - note case change)
    • If only the one required arg is given (read dir), writes to read dir.
    • If two args are given, checks if second is dir. If not assumes group. (careful - a misstyped dir could make for an ugly group name)
  • Warning: This will overwrite existing files without confirming!

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