DonationCoder.com Software > Post New Requests Here
IDEA: Command-line tool to move dir contents to existing subdirs
lanux128:
i'm glad you liked it, Cavalcader...
yes i agree. it is very difficult for a programmer who codes as a hobby to keep the program updated as frequent as we'd like it to be...
skrommel:
:) Try FileToFolder!
I've barely tested it, so please try it out on something unimportant! To use it, save to FileToFolder.ahk and go to www.autohotkey.com and download AutoHotkey.
FileToFolder - Moves files to subfolders, based on their name
Syntax: FileToFolder "<BaseFolder>" "<SubFolder>" <Overwrite> <Copy> "<PartOfFilename>" ["<PartOfFilename>" "++<PartOfFilname>" "--<PartOfFilname>"]
Example: FileToFolder "C:\Download" "Antivirus" "anti" "vir" "++.exe" "--.zip"
Moves all files containing anti or vir, and containing .exe and not containing .zip
from C:\Download to C:\Download\Antivirus
++ means the filname must contain the pattern
-- means the filname must not contain the pattern
Include the word Overwrite to replace existing files.
Include the word Copy to copy files instead of moving them.
Skrommel
--- ---;FileToFolder.ahk
; Moves files to subfolders, based on their name
;Skrommel @2006
If 0<3
Goto,ABOUT
basefolder=%1%
subfolder=%2%
ormatch=
andmatch=
notmatch=
overwrite=0
copy=0
Loop,%0%
{
If (A_Index<3)
Continue
param:=%A_Index%
If (param="Overwrite")
{
overwrite=1
Continue
}
If (param="Copy")
{
Continue
} StringLeft,action,param,2
If (action="++")
{
StringTrimLeft,param,param,2
andmatch=%andmatch%%param%`,
}
Else
If (action="--")
{
StringTrimLeft,param,param,2
notmatch=%notmatch%%param%`,
}
Else
ormatch=%ormatch%%param%`,
}
StringTrimRight,ormatch,ormatch,1
StringTrimRight,andmatch,andmatch,1
StringTrimRight,notmatch,notmatch,1
StringSplit,andmatch,andmatch,`,
count=0
Loop,%basefolder%\*.*,0,0
{
If A_LoopFileName Not Contains %ormatch%
Continue
If A_LoopFileName Contains %notmatch%
Continue
Loop,%andmatch0%
{
break=0
pattern:=andmatch%A_Index%
If A_LoopFileName Not Contains %pattern%
{
break=1
Break
}
}
If break=1
Continue
TrayTip,Moving %basefolder%\%subfolder%\%A_LoopFileName%
count+=1
IfNotExist,%basefolder%\%subfolder%
FileCreateDir,%basefolder%\%subfolder%
If copy=1
FileCopy,%basefolder%\%A_LoopFileName%,%basefolder%\%subfolder%\%A_LoopFileName%,%overwrite%
Else
FileMove,%basefolder%\%A_LoopFileName%,%basefolder%\%subfolder%\%A_LoopFileName%,%overwrite%
}
If copy=1
MsgBox,0,1 Hour Software by Skrommel - www.dcmembers.com\skrommel,FileToFolder copied %movecount% file(s)
Else
MsgBox,0,1 Hour Software by Skrommel - www.dcmembers.com\skrommel,FileToFolder moved %movecount% file(s)
Return
ABOUT:
about=FileToFolder
about=%about%`nMoves files to subfolders, based on their name
about=%about%`n
about=%about%`nSyntax: FileToFolder "<BaseFolder>" "<SubFolder>" <Overwrite> <Copy> "<PartOfFilename>" ["<PartOfFilename>" "++<PartOfFilname>" "--<PartOfFilname>"]
about=%about%`n
about=%about%`nExample: FileToFolder "C:\Download" "Antivirus" "anti" "vir" "++.exe" "--.zip"
about=%about%`n
about=%about%`n Moves all files containing anti or vir, and containing .exe and not containing .zip
about=%about%`n from C:\Download to C:\Download\Antivirus
about=%about%`n
about=%about%`n ++ means the filname must contain the pattern
about=%about%`n -- means the filname must not contain the pattern
about=%about%`n Include the word Overwrite to replace existing files.
about=%about%`n Include the word Copy to copy files instead of moving them.
about=%about%`n
about=%about%`nFor more tools and information, please stop by at
about=%about%`n https://www.donationcoder.com/Software/Skrommel
about=%about%`n
about=%about%`n1 Hour Software by Skrommel @2006
MsgBox,0,FileToFolder,%about%
Return
skrommel:
:tellme: I just fineread your post, Cavalcader, and you did actually request a somewhat different tool, with automatic matching of subfolders... But should it use the Or or the And parameter for matching? Or a parameter on it's own?
Skrommel
AbteriX:
*harrumph*
Reading this thread i am thinking about my start menu with a lot of items :)
I have clean up them bevor by hand and have move every folder
into an subfolder with his intial char.
Reading this thread i got fun to play around with AHK
and automat my next claening action with an script ;D
So i have writen this over the day in my rest times. (i call it 'Stefans 8 hour software' :( )
I am no pro! So use this on your own risk and with test files first!!!
The script works in that directory from where it is executed.
There are NO exceptions.... just create a dir (if not already exists) with an inital from 0-9 and from A- Z or smtg like '_'
and move ALL files/folders into that folders. That's all.
The script with comments; Move To Initial
; Autor: Stefan for www.DonationCoder.com
; Version: 0.1 , 2006-04-25
; Purpose: Move all files and folders of the current directory to an sub folder depending on the initial char of the file/folder name.
; :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; ::: S E T T I N G S :::
; ::: Overwrite existing files or cancel the move ?
FileMoveDirOverwrite=0
FileMoveOverwrite=0
; 0 (default): Do not overwrite existing files/folders. (Cancel the current move and Skip the current file/folder. You have to do some work manually)
; 1: Overwrite existing files. (Maybe you overwrite older files/folders you wanna keep? Be carefull with this option!)
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; ::: S C R I P T :::
; lines starting with a semicolon is only comment for your pleasure.
;Loop, FilePattern [, IncludeFolders?, Recurse?]
Loop, *.*,1,0
{
; skip the script-file itselfs, to not move it too.
; IF current LOOP the same as the name of the script ... GoTo start
IF A_LoopFileName=%A_ScriptName%
{
continue
; 'continue' means "Skip current loop and GoTo start"
}
; skip folder/file with name less then 2 char, to avoid loops (i.e. don't move e.g. folder 'A' to folder 'A'...)
;StringLen, OutputVar, InputVar
StringLen, Len, A_LoopFileName
IF (%LEN% < 2) continue
; we need only the first char of the folder/file name to create an new folder with this initial.
;StringLeft, OutputVar, InputVar, Count
StringLeft, InitialDir, A_LoopFileName, 1
; IF NOT ALREADY EXIST %InitialDir% MAKE A NEW folder %InitialDir%
IfNotExist,%InitialDir%
{
FileCreateDir, %InitialDir%
}
; MOVE Folder with name %A_LoopFileName% TO %InitialDir%
;FileMoveDir, Source, Dest [, Flag]
FileMoveDir, %A_LoopFileName%, %InitialDir%\%A_LoopFileName% , %FileMoveDirOverwrite%
; MOVE File with name %A_LoopFileName% INTO %InitialDir%
;FileMove, SourcePattern, DestPattern [, Flag]
FileMove, %A_LoopFileName%, %InitialDir% , %FileMoveOverwrite%
;Esc::ExitApp
; go to the begin and execute the next Loop
}
The pur script; Move To Initial
; Autor: Stefan for www.DonationCoder.com
; Version: 0.1 , 2006-04-25
; Purpose: Move all files and folders of the current directory to an sub folder depending on the initial char of the file/folder name.
; :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; ::: S E T T I N G S :::
; ::: Overwrite existing files or cancel the move ?
FileMoveDirOverwrite=0
FileMoveOverwrite=0
; 0 (default): Do not overwrite existing files/folders.
; 1: Overwrite existing files. (Maybe you overwrite older files/folders you wanna keep?)
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; ::: S C R I P T :::
Loop, *.*,1,0
{
IF A_LoopFileName=%A_ScriptName%
{
continue
}
StringLen, Len, A_LoopFileName
IF (%LEN% < 2) continue
StringLeft, InitialDir, A_LoopFileName, 1
IfNotExist,%InitialDir%
{
FileCreateDir, %InitialDir%
}
FileMoveDir, %A_LoopFileName%, %InitialDir%\%A_LoopFileName% , %FileMoveDirOverwrite%
FileMove, %A_LoopFileName%, %InitialDir% , %FileMoveOverwrite%
;Esc::ExitApp
}
The compiled exe (non overwrite version)
----
EDIT:
oh, i have overseen to finish the cancel option (ESC::ExitApp), i will try how to implement this option later.
(This option is for cancel the script if it is executed by accident or run into trouble)
Cavalcader:
should it use the Or or the And parameter for matching? Or a parameter on it's own?-skrommel (April 26, 2006, 09:00 AM)
--- End quote ---
Hmm, I'm not sure -- do you mean when moving filenames to existing folder named "antivirus" that match the pattern [ANTI or VIRUS] vs. [ANTI and VIRUS]?
Maybe a less complicated example is to sort music files as suggested by "app103" -- let's use that as a scenario. It could read a dir and look for very close similarities to existing subdirs, such that a subdir named Bing Crosby would match:
* Bing Crosby - song name.ogg
* Bing Crosby and David Bowie - Little Drummer Boy.wav
* Bob Hope & Bing Crosby - vaudeville sketch.mp3
This type of grouping might be made easier by the standardization of the naming convention; you'd have
artist space dash space title dot extension
...one can use a delimiter of " - " to make parsing easier and group by artist.
Another application using the original screensaver idea would be, using a subdir named Savers:
* spinning globe saver.zip
* screensaver switcher.exe
* savers to download.txt
In this case, you'd have to somehow tell it to match [root-word]* (resulting in saver* for that one) to have 'em all grouped.
Does that help?
Reading this thread i am thinking about my start menu with a lot of items
-AbteriX (April 26, 2006, 12:08 PM)
--- End quote ---
Good idea! But the program we talked about above, File Sieve, sounds perfect for that task. :)
By the way, I like your avatar! Is that a particular comic character, or did you make it?
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version