;RescueOprphans ;By jgpaiva ;date: June 2006 ;Function: see http://www.donationcoder.com/Forums/bb/index.php?topic=4046 ;set this parameter to the name of the root directory Start =D:\temp\test ;set the following parameter to false if you wouldn't like to be notified of files moved. Messages = true Loop,%Start%\*, 2, 0 { funct(A_LoopFileFullPath) } return funct(directory) { ;msgbox,%directory% FileCount := 0 Loop,%Directory%\*, 2, 0 { funct(A_LoopFileFullPath) } ;set the following line to "Loop, %Directory%\*, 0, 0" if you'd like the script to not move a file when there is only one file on the folder, but there are any folders. Loop, %Directory%\*, 0, 0 { FileCount += 1 FileName := A_LoopFileFullPath } If FileCount = 1 { SplitPath, FileName, OutFileName, OutDir, StringGetPos, Position, OutDir, \, R, StringLeft, NewDir, OutDir, %Position% If Messages msgbox, Move %OutFileName% from %OutDir% `nto %NewDir% FileMove, %OutDir%\%OutFileName%, %NewDir%\%OutFileName%, 1 } }