Batch program to move files to separate folders

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Montellese Offline
Team-XBMC Developer
Posts: 2,789
Joined: Jan 2009
Reputation: 20
Location: Switzerland
Post: #31
Nmarconi Wrote:Ahh yeah - must have been a typo that caused mov trailers to be missed and i wasn't thinking about ts files - ill fix the mov trailers and add ts files and upload version 3 when i get home tomorrow night.

Oh ok things like this keep happening to me as well ;-)

Another "problem" I had was with a movie file I was just watching which therefore couldn't be moved. Your program freezed and I had to hardcore kill it.

I don't know much about .NET but maybe it can be checked if a file is moveable or not.
find quote
garyi Offline
Posting Freak
Posts: 1,196
Joined: Oct 2008
Reputation: 0
Post: #32
Its possible automator in your apps folder could do this but I have no idea how.
find quote
Nmarconi Offline
Aeon Group
Posts: 77
Joined: Oct 2008
Location: Boston
Post: #33
Montellese Wrote:Oh ok things like this keep happening to me as well ;-)

Another "problem" I had was with a movie file I was just watching which therefore couldn't be moved. Your program freezed and I had to hardcore kill it.

I don't know much about .NET but maybe it can be checked if a file is moveable or not.

yeah, i can check the status of the file before i move it. kinda an obvious precaution to take - whoops :-). Like i said, i threw it together for myself first, then decided i should share it.

Ill add that and the other updates tonight.
find quote
Montellese Offline
Team-XBMC Developer
Posts: 2,789
Joined: Jan 2009
Reputation: 20
Location: Switzerland
Post: #34
Nmarconi Wrote:yeah, i can check the status of the file before i move it. kinda an obvious precaution to take - whoops :-). Like i said, i threw it together for myself first, then decided i should share it.

Ill add that and the other updates tonight.

Like I said I really appreciate your effort and work you put in this.

I know this myself, I develop a small tool for myself and think it works perfect because I always use it exactly the same way and never try something different. Then I give it to my brother or some friend and he comes back to me complaining about several strange behaviours ;-)
find quote
steve1977 Offline
Posting Freak
Posts: 1,577
Joined: Dec 2006
Reputation: 0
Post: #35
FernFerret Wrote:If you're using windows: This is what I use:
http://www.thehtpc.net/files/file2folder.rar

Article here: http://www.thehtpc.net/?s=rename

Unfortunately, none of the solutions in this threat work for me. The batch is super-supers-slow. The exe-file under link above starts, but gives error message below. Thanks for any thought or help!!!


>>>>>>>>>>>>>>>>>>>>>>>>>>
************** Exception Text **************
System.IO.IOException: Cannot create a file when that file already exists.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__Error.WinIOError()
at System.IO.File.Move(String sourceFileName, String destFileName)
at XBMC_Movies_Flat_to_Folders.Form1.btnOk_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
XBMC_Movies_Flat_to_Folders
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///E:/Filme/Sub-Filme/XBMC_Movies_Flat_to_Folders.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50b2b/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c571934f189/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b88b5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b04e6f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c821937e089/System.Data.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c291934e089/System.Xml.dll
----------------------------------------

Server: Asus Sabertooth Z77 | Intel Core i5 3.4 GHz | 12 GB DDR3 | 256 GB SSD, 40 TB (1 x 4 TB, 6 x 3TB, 9 x 2 TB)
HTPC 1: Apple Mac Mini (mid-2011) | Intel Core i5 2.5 GHz | 4GB DDR3 | 500 GB
HTPC 2: Apple Mac Mini (mid-2007) | Intel Core 2 Duo 2.0 GHz | 4 GB DDR2 | 16 GB SSD
find quote
Hitcher Offline
Skilled Skinner
Posts: 9,931
Joined: Aug 2007
Reputation: 67
Location: Eastleigh, UK
Post: #36
Try Rocky5's batch file.

Code:
@echo off
:prep
:: removes old files first if present and unhides them all
attrib -h "*.*"
del /q "List.txt"
del /q "DirList.txt"

:start
:: will add files that only exist to the list.txt
if exist "*.avi" dir /b "*.avi">>list.txt
if exist "*.bin" dir /b "*.bin">>list.txt
if exist "*.mkv" dir /b "*.mkv">>list.txt
if exist "*.rmvb" dir /b "*.rmvb">>list.txt
if exist "*.mp4" dir /b "*.mp4">>list.txt
if exist "*.iso" dir /b "*.iso">>list.txt
if exist "*.img" dir /b "*.img">>list.txt
if exist "*.vob" dir /b "*.vob">>list.txt
if exist "*.tbn" dir /b "*.tbn">>list.txt
if exist "*.nfo" dir /b "*.nfo">>list.txt
if exist "*-fanart.jpg" dir /b "*-fanart.jpg">>list.txt

:: removes the extensions of the files so that when creating folders it works
SetLocal EnableDelayedExpansion
For /F "tokens=* delims=" %%A in (list.txt) Do (
Set TxtLine=%%A
Set TxtLine=!TxtLine:.avi=!
Set TxtLine=!TxtLine:.rmvb=!
Set TxtLine=!TxtLine:.mkv=!
Set TxtLine=!TxtLine:.mp4=!
Set TxtLine=!TxtLine:.bin=!
Set TxtLine=!TxtLine:.iso=!
Set TxtLine=!TxtLine:.img=!
Set TxtLine=!TxtLine:.vob=!
Set TxtLine=!TxtLine:.tbn=!
Set TxtLine=!TxtLine:.nfo=!
Set TxtLine=!TxtLine:-fanart.jpg=!
echo !TxtLine!>>tmp.txt)
ren "tmp.txt" "DirList.txt"

:: does the hard work of creating and naming the files to match the folder
for /F "tokens=* delims=" %%a in (DirList.txt) do md "%%a"
for /f "tokens=* delims=" %%b in (DirList.txt) do set Folders=%%b
for /f "tokens=* delims=" %%c in (List.txt) do set Files=%%c

:: moves the files into there folders
move "%Files%" "%Folders%"

:: removes the files to start again
del /q "List.txt"
del /q "DirList.txt"

:: if a file of this type still exist it will try again
if exist "*.avi" goto start
if exist "*.mp4" goto start
if exist "*.rmvb" goto start
if exist "*.bin" goto start
if exist "*.mkv" goto start
if exist "*.iso" goto start
if exist "*.img" goto start
if exist "*.vob" goto start
if exist "*.tbn" goto start
if exist "*.nfo" goto start
if exist "*-fanart.jpg" goto start

:: cleans up after its done
del /q "List.txt"
del /q "DirList.txt"

Open Notepad and paste the code above, then Save As... 'Files2Folders.bat'.

[Image: sig_zps3af3b48e.jpg]
find quote
Nmarconi Offline
Aeon Group
Posts: 77
Joined: Oct 2008
Location: Boston
Post: #37
Have you tried my windows exe? Did you get this error with it? If so, PM me and i will get it to work for you.


steve1977 Wrote:Unfortunately, none of the solutions in this threat work for me. The batch is super-supers-slow. The exe-file under link above starts, but gives error message below. Thanks for any thought or help!!!


>>>>>>>>>>>>>>>>>>>>>>>>>>
************** Exception Text **************
System.IO.IOException: Cannot create a file when that file already exists.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__Error.WinIOError()
at System.IO.File.Move(String sourceFileName, String destFileName)
at XBMC_Movies_Flat_to_Folders.Form1.btnOk_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
find quote
AnalogKid Offline
Fan
Posts: 644
Joined: Feb 2009
Reputation: 141
Post: #38
Nmarconi Wrote:Have you tried my windows exe? Did you get this error with it? If so, PM me and i will get it to work for you.

If you change the batch file 'COPY' command to a 'MOVE' command it will be lightning quick... the copy (as stated) is for extreme safety
find quote
NetGuru87 Offline
Junior Member
Posts: 1
Joined: Aug 2009
Reputation: 0
Post: #39
Both of the mediafire links appear to not be working for v1 and v2 of your exe. I didn't see a v3 yet - could you upload it again please?
find quote
fowie Offline
Member
Posts: 75
Joined: Dec 2008
Reputation: 0
Post: #40
I whipped this together really quick, but it should work just fine. Makes a directory based on a movie's file name (checks if directory already exists) and then moves all the same named files (with different extensions) into the new directory. For example, my structure used to look like this:
A
--About_a_Boy-fanart.jpg
--About_a_Boy.mkv
--About_a_Boy.nfo
--About_a_Boy.tbn

after running this script:

A
--About A Boy <--- note spaces instead of underscores
----About_a_Boy-fanart.jpg
----About_a_Boy.mkv
----About_a_Boy.nfo
----About_a_Boy.tbn


Use it like this:
Code:
$ python rename.py DIRECTORY
where DIRECTORY is the directory you want it to do the renaming inside of, in the above example, I would put rename.py in the directory above A and then run:
Code:
$ python rename.py A

Get script here.
find quote