Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Create a folder for each file in a directory


  • Please log in to reply
8 replies to this topic
ZeroCool42
  • Members
  • 123 posts
  • Last active: Dec 24 2011 10:40 PM
  • Joined: 25 Apr 2009
I was reorganising my movie collection so that I could include information about the film to be read by a program such as XBMC. But, as it turns out to do that, each film needs to be in a separate folder, not good for my 300 or so avis dumped into one folder.

The solution: This little script. It will create a folder with the same name as every file in the directory it's in (minus the file extension), copy the file into the folder, then delete the original file.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Loop, %A_ScriptDir%\*.*, 0, 0 ;Loop through current directory, ONLY FILES. Do NOT recurse subfolders.
{
	If (A_LoopFileExt = "avi") 
	{
		LoopFileName = %A_LoopFileName%	
		LoopFileName := RegExReplace(LoopFileName, "\.avi")
		FileCreateDir, %LoopFileName%
		FileCopy, %A_LoopFileName%, %LoopFileName%
		FileDelete, %A_LoopFileName%
	}
}
Msgbox Tada!
Return


gamax92
  • Members
  • 411 posts
  • Last active: Aug 06 2013 05:00 AM
  • Joined: 05 Dec 2010
Why not just use FileMove?

ZeroCool42
  • Members
  • 123 posts
  • Last active: Dec 24 2011 10:40 PM
  • Joined: 25 Apr 2009

Why not just use FileMove?


Aha! I knew someone would ask me this :p.

Well, now in it's completed form, it's fine to use FileMove instead, but when I was building the script, I didn't just want to write it and let it loose on my movie collection, as potentially, there could have been problems with creating the folder or copying the file into it.

So in order to do a safe couple of tests, I simply commented out the FileDelete line and ran the script a couple of times for a couple of minutes each time. This way, I got to see if it worked, but there was no actual risk to my files.

Buuuut, like I say, now that I've used and tested it, it may easier to just use FileMove, but if anyone else is as paranoid as I am, they can go through the same tests before using the script.

Hope this answers your question :D

SKAN!
  • Guests
  • Last active:
  • Joined: --

if anyone else is as paranoid as I am, they can go through the same tests before using the script.


Sometime ago, one of my messy script garbled filenames so bad that I had to refer the torrent file and manually rename them back to proper names by referring their file sizes.. :(

ZeroCool42
  • Members
  • 123 posts
  • Last active: Dec 24 2011 10:40 PM
  • Joined: 25 Apr 2009

Sometime ago, one of my messy script garbled filenames so bad that I had to refer the torrent file and manually rename them back to proper names by referring their file sizes.. :(


Ow. Yes, I was worried about something similar. Essentially, I thought that because the folders created use the exact name of the files, I was worried that I might end up with illegal characters in directory names, causing the script to then try and copy files to these non-existent directories, and then delete the originals.

Of course, I'm sure with clever use of If ErrorLevel and similar could catch these before the script deleted the source file, but sometimes verification is just a little more reassuring than validation! :p

Hootie81
  • Members
  • 7 posts
  • Last active: Feb 01 2011 12:56 PM
  • Joined: 05 Jan 2011
I have been doing this manually for ages, helps keep everything looking neat and tidy. also really good when there is subtitle files or cd1 and cd2...

I really want a script that looks at the folder title, searches the net (IMDB or iMovie) and downloads the DVD cover and save it as folder.jpg and also a info.txt containing the plot and other info.

it would also be nice if it could put the dvd cover and plot and relevent info in a standard layout or format, then save as a picture, so when i plug the harddrive into my media player i can open it up to see what the movie is about.

ZeroCool42
  • Members
  • 123 posts
  • Last active: Dec 24 2011 10:40 PM
  • Joined: 25 Apr 2009
Hi Hootie81,

First of all, if you are wanting to coerce someone into writing a script for you, you should probably start your own thread, especially if you are not planning to write any code yourself.

Secondly, the reason I created this script was so that all my movies would be in their own folders. The reason I needed this to be the case was because I then used Media Companion to automatically grab the film metadata, images etc. for each.

Finally, if you don't like that solution, and are still planning on pursuing your own solution, bear this in mind, based on my experiences interacting with it through Media Companion, IMDB seems very temperamental in it's cooperation with automated scraping scripts. I hardly ever get successful results from it, and so use the other sources provided by Media Companion instead.

Hootie81
  • Members
  • 7 posts
  • Last active: Feb 01 2011 12:56 PM
  • Joined: 05 Jan 2011
I did kinda hope that someone would like the idea and take it up!

I have started looking at how to parse info from websites and started writing my own script. HTML is something i know nothing about which makes it harder. And like you say IMDB is aweful for getting info from.. hence the reason i was looking at moviei.com to scrape the info from as it has a nice layout and the search thows up much less crap.

I stumbled across this forum topic whilst looking for a way to grab the name of a folder to use to send to the search form...


I will have a better look at media companion in just a minute... looks like what i need!

But yes i shouldnt have hijacked this thread, sorry.

ZeroCool42
  • Members
  • 123 posts
  • Last active: Dec 24 2011 10:40 PM
  • Joined: 25 Apr 2009
Hi Hootie81,

First of all, don't worry, I do understand. Forum etiquette can be weird can confusing at first, just thought I should point this out before the mods did :p (Then again, I'm used to forums with much stricter posting rules so I may be overly paranoid about this :p)

Hmmm, I don't think HTML alone would do it, I think there'd probably be CSS and stuff like that you'd have to parse out as well. Best way I can think of to do it is to learn Regular expressions, and then you can just extract what you want from the page!

If you do go ahead with your project, feel free to drop me a PM if you need some help, my main project has gotten out of control and been put on hold, so I do occassionally have a spare minute or two atm.