Sign in to follow this  
Followers 0
jets

Creating txt files based on filenames and entering data into the txt files

5 posts in this topic

I used AutoIt way back and I am wondering if this can help me with a tedious task.

I have a folder with hundreds of media files that are named 'YEAR - NAME OF VIDEO - SOME HAVE EXTRA INFO AFTER THE HYPHEN.ext' What I would like to do is the following:

1) Create a txt file with the same filename as each media file

2) Have the txt file populated with template of xml parameters

3) Take the YEAR and NAME OF VIDEO - SOME HAVE EXTRA INFO AFTER THE HYPHEN portions of the filename and insert it into specific parts of the txt file

Is this possible using auto it? If so would you suggest the best way to accomplish this?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Yes its possible to do this with autoit. Take a look to this functions: StringRegExp to grab the infos from the file title. FileFindFirstFile, FileFindNextFile to show the filenames of all files in a specific directory. For the xml template, you have to show us how do you organize that :)

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Share this post


Link to post
Share on other sites

Indeed, AutoIt is the perfect tool for the job.

There are (AutoIt)Native functions for most of what you need and UDF wrapper functions for others.

For a quick example.

#include <Array.au3>
#include <File.au3>
$aFilesInFolder = _FileListToArray(@ScriptDir)
_ArrayDisplay($aFilesInFolder)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ok cool than Auto It can work. It's clear I'm lost. I will have to do some reading and figure out how to even attempt this! After thinking about it I am going to change the filenames using bulk renamer to have an episode number at the start of the filename. It'll look like '1,2,OR3 DIGIT EPISODE - YEAR - SOME HAVE EXTRA INFO AFTER THE YEAR/HYPHEN BEFORE TITLE - TITLE OF VIDEO.ext' Below is the txt file template I need to use:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<episodedetails>
<title>ALL TEXT AFTER THE YEAR IN FILENAME</title>
<showtitle>Disney Shorts</showtitle>
<season>1</season>
<episode>NUMBER AT START OF FILENAME BEFORE FIRST HYPHEN</episode>
<studio>Disney Studios</studio>
<displayseason>1</displayseason>
<displayepisode>4096</displayepisode>
</episodedetails>

I'm novice so I will try it out in the spare time I have over the next few days. Wish me luck!

Edited by jets

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try this:

;#include <Array.au3> ;Needed for _ArrayDisplay function

$File_Dir = @ScriptDir
$xml_path = @ScriptDir & "\Files_Info.xml"



Local $search = FileFindFirstFile($File_Dir & "\*.ext") ;Change the extension here

If $search = -1 Then
MsgBox(0, "Error", "No files/directories matched the search pattern")
Exit
EndIf

$xml_open = FileOpen($xml_path, 1)
FileWrite($xml_open, '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>')

While 1
$s_txt = ""
Local $file = FileFindNextFile($search)
If @error Then ExitLoop

$sRegex = StringRegExp($file, "([0-9]+) - ([0-9]+) - (.*?) - (.*?)\.", 3) ;With this regex you will grab any single part of text included between "-".
If @error Then ExitLoop
;_ArrayDisplay($sRegex) ;For debug only, so you can see what the regex do

$s_txt = '<episodedetails>' & @CRLF & _
'<title>' & $sRegex[2] & " " & $sRegex[3] & '</title>' & @CRLF & _
'<showtitle>Disney Shorts</showtitle>' & @CRLF & _
'<season>1</season>' & @CRLF & _
'<episode>' & $sRegex[0] & '</episode>' & @CRLF & _
'<studio>Disney Studios</studio>' & @CRLF & _
'<displayseason>1</displayseason>' & @CRLF & _
'<displayepisode>4096</displayepisode>' & @CRLF & _
'</episodedetails>' & @CRLF & @CRLF

FileWrite($xml_open, $s_txt)
WEnd

; Close the search handle
FileClose($xml_open)
FileClose($search)
MsgBox(0, "Done", "Finished!")
Exit

If you have other problem, don't esitate to post here ;)

Edit:

Successfully tested with this filename type:

12 - 2013 - Some Info - Title.ext
1 - 2013 - Some Info - Title.ext
100 - 2013 - Some Info - Title.ext

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0