tp546 39 Posted January 28, 2015 Share Posted January 28, 2015 hey guys, kind of a random request, but here is what i am trying to do: in the root of almost all my TV show folders, i have a file called "backdrop (2).jpg" that has a 16x9 logo for the show (this is due to an old image processing program i use). what I want to do is create a batch file that will go through all my TV folders and copy the "backdrop (2).jpg" file to a "thumb.jpg" file in the same folder, but only if there is not a thumb.jpg file in there already (preferably, if the "backdrop (2).jpg" is larger than the existing thumb, the "thumb.jpg" file would be renamed to "thumbbkp.jpg" but this isn't required). this is as far as i have been able to get with my batch file: For /R C:\Users\TP\Desktop\test %%G IN (backdrop *.jpg) do copy "%%G" "thumb.jpg" The problems I have are: I don't know how to correctly set the path on the last parameter I don't know how to prevent it from overwriting an existing thumb.jpg Let me know if anyone can help. Thanks! Link to comment Share on other sites More sharing options...
Macburp 109 Posted January 28, 2015 Share Posted January 28, 2015 What I think you need to do is set your TV Show folders as variables, and then reference that in the command. I recent created a script to do this in linux that I think may work for you - cd c:/'TV Folders' #the location of your TV folders progs = ( * ) #defines the list of all your sub-directories as an array for show in "${progs[@]%*/}"; do #this allows you to access each directory using the variable 'show' cd c:/'TV Folders'/$show/ copy "c:/users.../test/backdrop (2).jpg" # in quotes because of space in the file name An If statement should allow you to test for any existing thumb.jpg file. A little googling should give you the syntax for this, I'm really a windows man As I say, this is Linux, so I would suggest you download a copy of cygwin, which allows you to run linux scripts in windows. You can put the finished script into a windows batch file. This should give you a start, google is your friend. Good luck. Link to comment Share on other sites More sharing options...
shaefurr 1337 Posted January 28, 2015 Share Posted January 28, 2015 I don't know how to check for file size on the thumbs, but the regular for loop with an if statement to check for the thumb.jpg should work just fine. Here's a good example of a for loop and if statement for /r D:\temp %%a in (*) do ( if exist "C:\temp\%%~nxa" ( del "C:\temp\%%~nxa" /f /s /q ) else ( copy "%%a" C:\temp )) Link to comment Share on other sites More sharing options...
tp546 39 Posted January 28, 2015 Author Share Posted January 28, 2015 I don't know how to check for file size on the thumbs, but the regular for loop with an if statement to check for the thumb.jpg should work just fine. Here's a good example of a for loop and if statement for /r D:\temp %%a in (*) do ( if exist "C:\temp\%%~nxa" ( del "C:\temp\%%~nxa" /f /s /q ) else ( copy "%%a" C:\temp )) thanks but with that you aren't specifying the filename (backdrop (2).jpg) to start or to copy to (thumb.jpg) so I don't think that would work. Link to comment Share on other sites More sharing options...
chef 3746 Posted January 29, 2015 Share Posted January 29, 2015 One second. It won't be a batch I will write it vb.net. 1 Link to comment Share on other sites More sharing options...
chef 3746 Posted January 29, 2015 Share Posted January 29, 2015 (edited) @@tp546 I made this for you Renamer: https://dl.dropboxusercontent.com/u/46151346/Renamer/Renamer/bin/Release/Renamer.zip your anti-virus might flag the program because I didn't sign it or anything. Here is the code so you don;t think it's shady Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then TextBox1.Text = (FolderBrowserDialog1.SelectedPath) End If End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click For Each folder In IO.Directory.GetDirectories(TextBox1.Text) If IO.File.Exists(folder & "\" & TextBox2.Text) Then IO.File.Copy(folder & "\" & TextBox2.Text, folder & "\" & TextBox3.Text, True) IO.File.Delete(folder & "\" & TextBox2.Text) End If Next End Sub End Class Edited January 29, 2015 by chef 1 Link to comment Share on other sites More sharing options...
tp546 39 Posted January 29, 2015 Author Share Posted January 29, 2015 @@tp546 I made this for you Renamer: https://dl.dropboxusercontent.com/u/46151346/Renamer/Renamer/bin/Release/Renamer.zip your anti-virus might flag the program because I didn't sign it or anything. Here is the code so you don;t think it's shady Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then TextBox1.Text = (FolderBrowserDialog1.SelectedPath) End If End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click For Each folder In IO.Directory.GetDirectories(TextBox1.Text) If IO.File.Exists(folder & "\" & TextBox2.Text) Then IO.File.Copy(folder & "\" & TextBox2.Text, folder & "\" & TextBox3.Text, True) IO.File.Delete(folder & "\" & TextBox2.Text) End If Next End Sub End Class wow thanks so much - do i just put it in the root folder of my TV library and run it? Link to comment Share on other sites More sharing options...
tp546 39 Posted January 29, 2015 Author Share Posted January 29, 2015 wow thanks so much - do i just put it in the root folder of my TV library and run it? so i just tested it and it works except one thing - can it copy the file instead of rename it so the original remains intact? (so backdrop (2).jpg would exist afterward in all cases) Link to comment Share on other sites More sharing options...
chef 3746 Posted January 29, 2015 Share Posted January 29, 2015 so i just tested it and it works except one thing - can it copy the file instead of rename it so the original remains intact? (so backdrop (2).jpg would exist afterward in all cases) Yeah! I will fix it in a second Link to comment Share on other sites More sharing options...
chef 3746 Posted January 29, 2015 Share Posted January 29, 2015 (edited) @@tp546 Here you go https://dl.dropboxusercontent.com/u/46151346/Renamer/Renamer/bin/Release/RenamerJust%20copy.zip Edited January 29, 2015 by chef 2 Link to comment Share on other sites More sharing options...
tp546 39 Posted January 29, 2015 Author Share Posted January 29, 2015 @@tp546 Here you go https://dl.dropboxusercontent.com/u/46151346/Renamer/Renamer/bin/Release/RenamerJust%20copy.zip thanks so much! Link to comment Share on other sites More sharing options...
chef 3746 Posted January 29, 2015 Share Posted January 29, 2015 Anytime. There is no error handling in it so it will crash if the text box are empty... Lol! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now