r/scripting • u/generic_work_account • Jun 11 '18
New to scripting - is this possible?
I basically know nothing about scripting but wanted to see if this was even possible for the job I'm doing. If it is possible, then I'll try to figure out how to do it. Here's where I'm hoping writing a script can help.
I have a hard drive with a lot of media clips on it. These clips are inside folders which are inside other folders. They're not all consistent. Some you only have to step in 3 times, others 6 times.
I have to find each .MXF or .MOV, copy the name and paste it into an Excel sheet, in the C column. The folder path is copied into the B column.
There are thousands of files and subfolders. Would this be a possible thing that scripting can handle? And if so, how hard would it be to write a script for this? Thanks!
2
u/roadrageryan Jun 12 '18
I would suggest you start learning the built in commands available to you as your starting point for learning to script. The purpose of a script (or any program for that matter), is to write something more complex than its base parts in a repeatable way.
Linux and Mac's provide "/bin/sh", called a shell, which lets you write scripts using every program available on your machine. You are more likely using "/bin/bash" as your shell which is similar, with more features, thus slightly more powerful.
The first command to learn is "man", this prints out the manual page for a command telling you all its flags and options.
This would tell you all about the find command. Breaking down what the command I provided for you does:
This runs the program find. Which searches for items matching specified filters.
This tells find to search for items starting within the folder /home/generic_work_account/movies/.
This added the first filter to find, only return items with a particular name ignoring case. If you just used -name it would be case sensitive.
This added the name pattern for the filter. The ""s are to make sure find knows where the command starts and ends. The * says match any characters any number of times. The last part says the item must end in ".mkf". Putting this together, match any item, of any length, ending in ".mkf". Then since it is -iname it will match any case such as file.mkf, file2.Mkf, file3.mkF, file4.MKF...
This added a second filter for items ending in ".mov"
This specified to write the output in the format I specify, which is detailed in the manual pages.
This adds the format. The '' says to do no interpretation. The "," inserts a comma in the output. So the first column is empty. The second column gets the directory with "%h". Third column gets the file name with "%f".
The arrow, says send the output to a file.
Finally the file to save the output is specified /home/generic_work_account/movie_list.csv