mIRC Home    About    Download    Register    News    Help

Print Thread
file organizer #124456 07/07/05 12:01 AM
Joined: Mar 2005
Posts: 27
N
Name141 Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2005
Posts: 27
i'm trying to make a file organizer that'll read a DIR and it's sub DIRs and place files that look 'matching' in a DIR with that name. Such as ,
HIFiles.txt
HiFiles.jpg
HiFiles.zip
Chickens.zip
Chickens.txt

would make hifiles a DIR , and place hifiles.txt/jpg/zip in the hifiles DIR, and same with chickens.

some people came up with this for me, //window -sh @list | var %a = $findfile(C:\test,*,0,aline @list $1-) | savebuf @list listx.txt | run listx.txt

to save the files to a txt, then i'm lost mad

maybe there would be a way to use $read() to gather patterns and move them to a DIR ? If someone comes up with a method, could you also make it easy to check for 2 or more " patterns " to check for insted of just one if needed ?

Re: file organizer #124457 07/07/05 03:18 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
This is untested, as I normally sort my files manually. For the few times I'd actually want to have a code to do it, it's not really worth it. However, I think this will do what you're asking for
Code:
 ;usage /filesort <directory> <pattern(s)>
alias filesort {
  if (!$1) { .msg $nick No directory specified }
  elseif (!$isdir($1)) { .msg $nick Directory $1 not found }
  elseif (!$2) { .msg $nick No file pattern specified }
  elseif (!$isdir($2)) { .md $2 }
  else {
    var %a = 1
    while %a <= $numtok($2-,32) {
      set %file $gettok($2-,%a,32)
      var %b = 1
      while %b <= $findfile($1,$+($2,.*),0) {
        .rename $findfile($1,$+(%file,.*),%b) $+(%file,\,$findfile($1,$+(%file,.*),%b))
        inc %b
      }
      inc %a
    }
  }
}
 

The directory specified is the starting directory for the search
multiple patterns are allowed, with each pattern being separated by spaces.
pattern is to be in the format of "name" only...no extensions

Re: file organizer #124458 07/07/05 05:12 AM
Joined: Mar 2005
Posts: 27
N
Name141 Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2005
Posts: 27
i'm looking to automatically do everything, 1,000+ files will be sorted.

here's something like i'd be trying to do

if (something isin thisgroup) { move something thisgroup }
continue checking for grouped files..... and moving


also i'd like something to be able to ignore a "pattern" to look for. for like this....

1-chickens.mp3
2-chickens.mp3
hi-chickens.mp3
nomorechickens.txt
1-pizzas.txt
2-pizzasforyou.mp3

if i could "ignore 1,2" etc, it wouldn't be faulty and mess up putting 1-chickens and 1-pizzas in the same DIR.

Re: file organizer #124459 07/07/05 05:26 AM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
I came up with this, before you mentioned the files were numbered like that
Code:
alias sort2dir {
  window -sh @filelist
  var %sourcedir = $sdir(*)
  write -c %sourcedir $+ _List.txt
  .echo -q $findfile(%sourcedir,*,0,1,nowdir $1-)
  listdone %sourcedir
}
alias nowdir {
  var %currentFN = $nopath($1-)
  var %currentfnLEN = $calc($len(%currentFN) - 4) 
  var %currentfnSTRIP = $left(%currentFN,%currentfnLEN)
  var %currentDIR = $nofile($1-)
  if (!$isdir(%currentDIR $+ %currentfnSTRIP)) { mkdir %currentDIR $+ %currentfnSTRIP }
  .rename $1- %currentDIR $+ %currentfnSTRIP $+ \ $+ %currentFN
  aline @filelist %currentDIR $+ %currentfnSTRIP $+ \ $+ %currentFN
}
alias listdone {
  var %sourcedir = $1-
  savebuf @filelist %sourcedir $+ _List.txt
  run %sourcedir $+ _List.txt
  window -c @filelist
}


you should test it in a folder with just a few files in it
I did not test it for files with spaces in the path or file name, so it might need tweaking for that.

Re: file organizer #124460 07/07/05 06:46 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Yikes...not quickly I can't...I'll think it over, and see what I can come up with, but at the moment that seems extemely difficult

Re: file organizer #124461 07/07/05 07:00 AM
Joined: Mar 2005
Posts: 27
N
Name141 Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2005
Posts: 27
that worked to a point, but it didn't scan the sub dirs, and didn't work with spaces (as predicted). And that made tons of 1, 2, 3 etc.. and placed files i wanted to group in them, so i guess numbers should be excluded, and only letters looked at.

i was thinking.... maybe a hashtable, and regex of some sort would be best. Maybe if 2 things are the same in the file name, it'd treat it as a "group" and know to group them.

Re: file organizer #124462 07/07/05 07:03 AM
Joined: Mar 2005
Posts: 27
N
Name141 Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2005
Posts: 27
yes, i'm thinking maybe i'm looking at the wrong scripting for this idea lol. but I figgure mIRC would have some kinda way of pulling it off easier than some shell script.

Re: file organizer #124463 07/07/05 10:44 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
You need to be more specific about the grouping rules. Tells us exactly which substrings should be ignored, giving a lot of examples, including negative ones: give examples of files that should be grouped together and as well as ones of files that should not. Be as clear as possible. Here's an example of examples :tongue: you could give:

hotchickens.txt
hotdogs.txt
coldchickens.txt

First of all, are there going to be files like this (ie ones that share different substrings)? If yes, should hotchickens.txt be grouped with hotdogs.txt (because of "hot") or should it be grouped with coldchickens.txt (because of "chickens")? Try to translate the rules to something that can be programmed, e.g. "all files of the same food should be put together" doesn't say much, but "all file names that end in the same string of letters should be put together" does say something about the coding approach.

It would be even better if you figured out the algorithm yourself and only asked us to implement it in mirc.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: file organizer #124464 08/07/05 12:01 AM
Joined: Mar 2005
Posts: 27
N
Name141 Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2005
Posts: 27
well it's hard to understand kinda, but.. lets say this is what i want sorta, beats me what kind of things i'd be using though but lets just say it was like "on text"

it'd be something like this:

on *:text:*:*:{ if (($numbers isin 1-) && (%nonumbers == on)) { replace #'s with $null }
if (%thingstoignore isin $1-) { replace ignored things with $null }
if ($1- isin %havethegroupsaved)
{ move file to groupDIR }
if ($1- !isin %havegroupsaved) { if ($read(lists.txt,make it read all of the lists) == 1 ) { make the group and make a new dir moving the files there that match the group }
}

alias numbers {
1234567890
}

but could it be stronger and do like it checks for 2 or more common things in the file names (able to turn it on and off, or maybe actually SET it to the # you want?) ? like say..

Cows_go_moo.txt
Cows_go_hi.txt
Cows_Come_for_you1.txt
Cows_Come_for_you2.txt

and it'd make "cows" as a DIR, but inside the DIR, it'd make "go" , and put Cows_go_moo.txt, and Cows_go_hi.txt inside of cows/go , and then it'd make 'come' , and put the files Cows_Come_for_you1.txt ,Cows_Come_for_you2.txt in cows/come .

Re: file organizer #124465 08/07/05 02:53 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
This is sounding, more and more, like something you should do manually, then once a week check for any changes...unless there's going to be a lot of changes on, say, a daily basis.

Sorry to say it, but what you asked for originally was fairly simple, and it's gotten more complex on an almost exponential scale.

If what you want to do, can be done via scripting...3 cheers to the person that manages it

Re: file organizer #124466 08/07/05 06:01 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
i bet the files end in .mp3 not .txt

Re: file organizer #124467 08/07/05 05:29 PM
Joined: Mar 2005
Posts: 27
N
Name141 Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2005
Posts: 27
what's the difference in what extentions?
(as in i'm asking for a file organizer by names, not extention)

Last edited by Name141; 08/07/05 05:30 PM.
Re: file organizer #124468 08/07/05 05:37 PM
Joined: Mar 2005
Posts: 27
N
Name141 Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2005
Posts: 27
maybe something like a file reader to put the files in a hash table.

then have some alias to split them up, such as:

if ($hget(files,1) == $hget(files,2)) { make the group and dir }

but how do i make $hget scan the whole table ? and how do i get the files to a table?

Re: file organizer #124469 08/07/05 06:11 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Quote:
what's the difference in what extentions?
(as in i'm asking for a file organizer by names, not extention)


The point being that:

1) MP3s are usually what people have with such weird naming schemes (that or porn)... anything else is usually named properly.

2) MP3s are illegal.

3) mIRC isn't a filesharing application.


All that said, you can sort things much more quickly manually than trying to make a script that can handle every possible grouping that you are talking about. There is no easy way to do what you want because mIRC (or any software) can't distinguish between what makes sense to you to group and what doesn't. It can only group by specifically designed methods (such as if the first X letters match, or whatever). What you want to do is much more complicated than anyone here is likely to even attempt to take on.


Invision Support
#Invision on irc.irchighway.net
Re: file organizer #124470 08/07/05 10:02 PM
Joined: Mar 2005
Posts: 27
N
Name141 Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2005
Posts: 27
I figgure it could be done by making a table with the names, and finding a way to split the names in parts.

such as

chickens_con_caso
chickens_with_rice

if there was a way to split up spacing and other forms of none needed things that'd be understood as a space in a file name (such as space,_,comma,.,etc) .

Thus if i'm correct it should give something like:

is there common first words in the files? yes
chickens
there for:
chickens == chickens { it's a group make the dir }
is chickens in $2? no { make new subdir move the file there }
check for 3rd chicken in first word of files, if so go back to chickens == chickens , continue on with other new groups

ending in:
chickens/con/chickens_con_caso
chickens/with/chickens_with_rice

so i'm thinking, make a table with info of the files.
split the files up in a new table, use the first one to make commands move and make new DIR (cause it has the files location and real names. )

but maybe i'm in over my head?

edit: table = hashtable

Re: file organizer #124471 08/07/05 10:19 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I notice you didnt say they werent mp3's so ill assume they are now.

ignoring the fact
1) MP3s (for the most part) are illegal copies of music.
2) mIRC isn't a filesharing application, and were not ment to help with illegal activities.

Im going to give the benifit of doubt and say maybe there free to distribute mp3's
If mp3's do u relaize that alot of them have an mp3 tag (id3 tag) inside them with data on the song/artist etc etc, this can be used for very effective sorting.
A program like this can be used with great speed to either organize or rename for an organizer to sort.

While its not soley automated, i doubt you ever could, since the filenameing is prettywell random, but the data held in the tag is 90% or more correct most times.

Re: file organizer #124472 09/07/05 02:34 AM
Joined: Mar 2005
Posts: 27
N
Name141 Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2005
Posts: 27
to continue on development it seems i must clear up it's not:
ogg/monkeys audio/mp3/mp3pro/wav/etc audio files.

Re: file organizer #124473 09/07/05 06:07 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
;Usage /file.organizer source folder or $file.organizer(source folder)
; Use /.file.organizer or $file.organizer to suppress outputs
; Returned values = -1 : invalid source directory
;                   0+ : processed files (does not always mean this many files were moved (see note below))
;
; NB: Due to attempts to create folders when files of the same name already exist and/or attempts to move(rename) files when the same file name 
;     already exists not all files well always be moved. This problem is unavoidable but should represent less than 2% of all files proccessed.
;
alias file.organizer {
  if (!$isdir($1-) || ($mircdir == $1-)) { if ((!$isid) && ($show)) { echo -sce info * Invalid folder specified for /file.organizer $1- * } | return -1 } 
  var %show = $iif((!$isid && $show),$true,$false), %sourcefolder = $1-, %proccessed = $findfile($1-,*.*,0,1,!.echo -q $subfolder.a.file(%show,%sourcefolder,$nopath($1-)))
  if ((!$isid) && ($show)) { echo -sce info * /file.organizer processed %proccessed file(s) in $1- * } | return %proccessed
}
;
alias -l subfolder.a.file {
  var %foldername = $iif(($pos($3,.,0)),$left($3,$calc($pos($3,.,$v1) - 1)),$3)
  !.echo -q $regsub(%foldername,/[^[:alpha:]]+/g,/,%foldername)
  if ($numtok(%foldername,47) > 1) { var %foldername = $deltok(%foldername,-1,47) } | else { var %foldername = $gettok(%foldername,1-,47) }
  var %m = $numtok(%foldername,47), %i = 1
  while (%i <= %m) { mkdir $+(",$2,/,$gettok(%foldername,$+(1-,%i),47),") | inc %i }
  if $isdir($+($2,/,%foldername)) { $+($iif(!$1,.),rename) $+(",$2,/,$3,") $+(",$2,/,%foldername,/,$3,") }
  :error | reseterror
}


Try that out, you call it using /file.organizer foldername
foldername is of course a valid folder you want organizing

it well take any file in that folder, remove all non alphabetic characters, leaving the remainder as seperate words ie:
this-big-file.txt becomes this big file.txt
it well then attempt to create the folder structure based on these words (excluding the last word, and extention, unless there is only one word)
this-big-file.txt becomes this\big\this-big-file.txt
this.txt becomes this\this.txt
file becomes file\file
123file.ext becomes file\123file.ext
123this456big789file.blah becomes this\big\123this456big789file.blah
@@@1.txt becomes @@@1.txt(because there is no foldername to place it into)

Re: file organizer #124474 10/07/05 03:18 AM
Joined: Mar 2005
Posts: 27
N
Name141 Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Mar 2005
Posts: 27
that works very very close to what i want. However, can it halt after reading 2 words of the file name (during the making of the DIRs that is) , and have a counter part to grab all the files in a dir, and it's sub dirs, and place them in to a DIR that will be sorted out with it later, so i don't have to dig all pre sorted files out of the folders and place them in the big DIR?

Such as move all the files to a temp dir with it's counterpart, delete all the crap in the DIR after finding the files, take the files it got out of the sub folders and folders (that it just deleted the structure of) and put them back organized?

or maybe just a counter part to move all the files to a new DIR, and i can sort the new DIR , so i don't have to put all the files in C:\hi , out of C:\hi\1 , etc..

Last edited by Name141; 10/07/05 03:25 AM.
Re: file organizer #124475 11/07/05 12:49 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
[code];
;
;
;
;Usage /file.organizer source folder or $file.organizer(source folder)
; Use /.file.organizer or $file.organizer to suppress outputs
; Returned values = -1 : invalid source directory
; 0+ : processed files (does not always mean this many files were moved (see note below))
;
; NB: Due to attempts to create folders when files of the same name already exist and/or attempts to move(rename) files when the same file name
; already exists not all files well always be moved. This problem is unavoidable but should represent less than 2% of all files proccessed.
;
alias file.organizer {
if (!$isdir($1-) || ($mircdir == $1-)) { if ((!$isid) && ($show)) { echo -sce info * Invalid folder specified for /file.organizer $1- * } | return -1 }
var %show = $iif((!$isid && $show),$true,$false), %sourcefolder = $1-, %processed = $findfile($1-,*.*,0,1,!.echo -q $subfolder.a.file(%show,%sourcefolder,$nopath($1-)))
if ((!$isid) && ($show)) { echo -sce info * /file.organizer processed %processed file(s) in $1- * } | return %processed
}
alias -l subfolder.a.file {
var %foldername = $iif(($pos($3,.,0)),$left($3,$calc($pos($3,.,$v1) - 1)),$3)
!.echo -q $regsub(%foldername,/[^[:alpha:]]+/g,\\,%foldername)
var %foldername = $gettok(%foldername,1-2,92)
var %m = $numtok(%foldername,92), %i = 1
while (%i <= %m) { mkdir $+(",$2,\,$gettok(%foldername,$+(1-,%i),92),") | inc %i }
if $isdir($+($2,\,%foldername)) { $+($iif(!$1,.),rename) $+(",$2,\,$3,") $+(",$2,\,%foldername,\,$3,") }
:error | reseterror
}
;
;
;
;
;Usage /blitz.folders target folder or $blitz.folders(target folder)
; Use /.blitz.folders or $blitz.folders to suppress outputs
; Returned values = -1 : invalid target directory
; 0+ 0+ : value 1 is processed files (does not always mean this many files were moved (see note below))
; value 2 is processed folders (does not always mean this folder was erased (see note below))
;
; NB: Due to attempts to attempts to move(rename) files when the same file name already exists and/or file access errors not all files well always be moved.
; This problem then migrates to folder erasing as folders can not be erased when files are still present.
; This problem is unavoidable but should represent less than 5% of all files/folders proccessed.
;
alias blitz.folders {
if (!$isdir($1-) || ($mircdir == $1-)) { if ((!$isid) && ($show)) { echo -sce info * Invalid folder specified for /blitz.folders $1- * } | return -1 }
var %show = $iif((!$isid && $show),$true,$false), %sourcefolder = $+($1-,$iif(($right($1-,1) != \),\)), %processed.files = $findfile($1-,*.*,0,999,!.echo -q $unsubfolder.a.file(%show,%sourcefolder,$1-))
if ((!$isid) && ($show)) { echo -sce info * /blitz.folders processed %processed.files file(s) in $1- * }
var %blitz.folders.hashtable = $+(blitz.folders.hashtable.,$ticks,.,$mid($rand(1000000,1999999),2)) | hfree -w %blitz.folders.hashtable
var %processed.folders = $finddir($1-,*.*,0,999,hadd -m %blitz.folders.hashtable $+(item,$hget(%blitz.folders.hashtable,0).item) $1-), %i = %processed.folders
while (%i) { dec %i | $remove.a.folder($hget(%blitz.folders.hashtable,$+(item,%i))) } | hfree -w %blitz.folders.hashtable
if ((!$isid) && ($show)) { echo -sce info * /blitz.folders processed %processed.folders folder(s) in $1- * }
return %processed.files %processed.folders
}
alias -l unsubfolder.a.file {
if ($nofile($3) != $2) { $+($iif(!$1,.),rename) $+(",$3,") $+(",$2,$nopath($3),") }
:error | reseterror
}
alias -l remove.a.folder {
rmdir $+(",$1,")
:error | reseterror
}[code]

* i corrected something odd i had done using / instead of \ for folder seperators (i use both on different systems, mirc handles both but makes them all \)
* I corrected a spelling error with the word "proccessed" -> "processed"
* I changed it so it only makes 2 folder depths
* Created a /blitz.folders alias that reverses the process, it actually takes any files from any subfolders of the target folder and dumps them in the target folder, then deletes the subfolders

PS: to anyone who noticed the 999 in the $FINDFILE/DIR thats deliberate, i watched mirc lockup one day on a faulty directory link to a higher up the tree folder