Skip to content

Instantly share code, notes, and snippets.

@servel333
Created September 20, 2013 19:39
Show Gist options
  • Save servel333/6642752 to your computer and use it in GitHub Desktop.
Save servel333/6642752 to your computer and use it in GitHub Desktop.
Small Ruby script to generate a Notepad++ workspace from a path recursively.
# this.rb c:/path/to/scan > npp.workspace.xml
def puts(*args)
Kernel.puts *args
end
def scan_path(parent, indent='')
paths = Dir.glob(File.join(parent, '*'))
paths.select{ |path| !File.directory? path }.sort.each do |file|
puts indent+'<File name="'+file+'" />'
end
paths.select{ |path| File.directory? path }.sort.each do |directory|
filename = File.basename(directory)
puts indent+'<Folder name="'+filename+'">'
scan_path directory, indent+' '
puts indent+'</Folder>'
end
end
if (ARGV[0].nil?)
abort 'Path required'
end
root = ARGV[0]
puts '<NotepadPlus>'
puts ' <Project name="'+root+'">'
scan_path(root, ' ');
puts ' </Project>'
puts '</NotepadPlus>'
#<NotepadPlus>
# <Project name="Project name (can be any string)">
# <Folder name="folder name (can be any string)">
# <Folder name="folder name (can be any string)">
# <File name="full path to file" />
# </Folder>
# </Folder>
# </Project>
#</NotepadPlus>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment