Posted by member 37809 on 2006-06-13 21:12:49 link
*boost*
I took a foray into JScript yesterday and this is what I came up with;
it will sort module docs into subdirs like this:
r\rarrr\0.1pre.html
s\simplemod\0.2.txt
m\modulename\ver.si.on\has.txt
m\modulename\ver.si.on\many.png
m\modulename\ver.si.on\files.html
I chose this format for use with a PopupDynamicFolder.
The code is meant to be compressed rather than obfuscated. guess I got bored.
EDIT: I lied. Obfuscation seems like an act of desperation, when done manually. Let's be proper now:
I took a foray into JScript yesterday and this is what I came up with;
it will sort module docs into subdirs like this:
r\rarrr\0.1pre.html
s\simplemod\0.2.txt
m\modulename\ver.si.on\has.txt
m\modulename\ver.si.on\many.png
m\modulename\ver.si.on\files.html
I chose this format for use with a PopupDynamicFolder.
// this goes in \litestep\modules\docs\sortdocs.js
s=new ActiveXObject('Scripting.FileSystemObject')
n=0
a={}
r=s.GetFolder('.')
b='\\\\'
for(e=new Enumerator(r.subfolders);!e.atEnd();e.moveNext())a[n++]=e.item()
for(e=new Enumerator(r.files);!e.atEnd();e.moveNext())a[n++]={f:e.item()}
for(f in a){f=a[f]
e=f.f
f=e?e:f
n=f.name
if(m=n.match(/([^-]+)-(.+)/)){
s.FolderExists(c=r.path+b+n.charAt(0))?0:s.CreateFolder(c)
s.FolderExists(c+=b+m[1])?0:s.CreateFolder(c)
c+=b+m[2]
e?s.FileExists(c)?0:f.move(c):s.FolderExists(c)?0:f.move(c)}}
s=new ActiveXObject('Scripting.FileSystemObject')
n=0
a={}
r=s.GetFolder('.')
b='\\\\'
for(e=new Enumerator(r.subfolders);!e.atEnd();e.moveNext())a[n++]=e.item()
for(e=new Enumerator(r.files);!e.atEnd();e.moveNext())a[n++]={f:e.item()}
for(f in a){f=a[f]
e=f.f
f=e?e:f
n=f.name
if(m=n.match(/([^-]+)-(.+)/)){
s.FolderExists(c=r.path+b+n.charAt(0))?0:s.CreateFolder(c)
s.FolderExists(c+=b+m[1])?0:s.CreateFolder(c)
c+=b+m[2]
e?s.FileExists(c)?0:f.move(c):s.FolderExists(c)?0:f.move(c)}}
The code is meant to be compressed rather than obfuscated. guess I got bored.
EDIT: I lied. Obfuscation seems like an act of desperation, when done manually. Let's be proper now:
// this goes in \litestep\modules\docs\sortdocs.js
var fso = new ActiveXObject('Scripting.FileSystemObject');
var todo = [];
var e, root = fso.GetFolder('.');
e = new Enumerator(root.subfolders);
for (e.moveFirst(); !e.atEnd(); e.moveNext()) {
todo.push({ item: e.item() });
}
e = new Enumerator(root.files);
for (e.moveFirst(); !e.atEnd(); e.moveNext()) {
todo.push({ item: e.item(), is_file:1 });
}
for (var i=0, item; item = todo[i]; i++) {
var caps, dest, file = item.item;
if (caps = file.name.match(/([^-]+)-(.+)/)) {
dest = root.path +'\\\\'+ file.name.charAt(0);
if (!fso.FolderExists(dest)) fso.CreateFolder(dest);
dest += '\\\\'+ caps[1];
if (!fso.FolderExists(dest)) fso.CreateFolder(dest);
dest += '\\\\'+ caps[2];
if (item.is_file) {
if (!fso.FileExists(dest)) file.move(dest);
}
else if (!fso.FolderExists(dest)) file.move(dest);
}
}
var fso = new ActiveXObject('Scripting.FileSystemObject');
var todo = [];
var e, root = fso.GetFolder('.');
e = new Enumerator(root.subfolders);
for (e.moveFirst(); !e.atEnd(); e.moveNext()) {
todo.push({ item: e.item() });
}
e = new Enumerator(root.files);
for (e.moveFirst(); !e.atEnd(); e.moveNext()) {
todo.push({ item: e.item(), is_file:1 });
}
for (var i=0, item; item = todo[i]; i++) {
var caps, dest, file = item.item;
if (caps = file.name.match(/([^-]+)-(.+)/)) {
dest = root.path +'\\\\'+ file.name.charAt(0);
if (!fso.FolderExists(dest)) fso.CreateFolder(dest);
dest += '\\\\'+ caps[1];
if (!fso.FolderExists(dest)) fso.CreateFolder(dest);
dest += '\\\\'+ caps[2];
if (item.is_file) {
if (!fso.FileExists(dest)) file.move(dest);
}
else if (!fso.FolderExists(dest)) file.move(dest);
}
}