Page 1 of 1

rename tv show to file name with the following script

Posted: October 3rd, 2014, 2:22 pm
by phairplay
Hi guys,

I'm getting increasing tv shows with random tiles and would really like your help resolve this issue which would keep my wife happy when I'm away for work.

most of the shows shes watches are watched and deleted, therefore I had the following script created for me

Code: Select all

@echo off

for /f "tokens=*" %%c in ('dir/b/a-d %1 ^| find /v /c "::"') do set filecount=%%c

if %filecount% LEQ 5 (
cd /d %1
for /f "tokens=*" %%f in ('dir /a-d /b') do if not exist "..\%%f" ( 
echo Moving %%f...
move "%%f" ".."
)
cd ..
echo Deleting folder...
rd %1
) else (
echo To many files to move, aborting...
)
this downloads the and removed the required file from it's folder and deletes the unwanted folder.

how do I use this and rename the file at the same time?

thanks

Re: rename tv show to file name with the following script

Posted: October 3rd, 2014, 2:50 pm
by shypike
Rename the file to what?
What's the relation between the name and your script?

Re: rename tv show to file name with the following script

Posted: October 3rd, 2014, 4:30 pm
by phairplay
I'm looking for something that will rename the file to the name of the nzb
As I'm getting a lot recently that are a random set of numbers and letters.

I was wondering if this could be added to the script that dumps all my tv shows into one folder for easy viewing

Re: rename tv show to file name with the following script

Posted: October 3rd, 2014, 6:24 pm
by mrg9999
I use this powershell I found. Change extension to required one.
###########################################################
# AUTHOR : Marius @ Hican - http://www.hican.nl - @hicannl
# DATE : 23-04-2012
# COMMENT : This script renames all .mkv files to the
# name of the .mkv parent folder recursively,
# extended with an increasing number.
# Put the script in the root of the folders'
# parent folder.
# NOTE: This script can also be used for renaming
# other / multiple files, just adjust the filter!
###########################################################
$path = Split-Path -parent $MyInvocation.MyCommand.Definition

Function renameFiles
{
# Loop through all directories
$dirs = dir $path -Recurse | Where { $_.psIsContainer -eq $true }
Foreach ($dir In $dirs)
{
# Set default value for addition to file name
$i = 1
$newdir = $dir.name + "_"
# Search for the files set in the filter (*.mkv in this case)
$files = Get-ChildItem -Path $dir.fullname -Filter *.mkv -Recurse
Foreach ($file In $files)
{
# Check if a file exists
If ($file)
{
# Split the name and rename it to the parent folder
$split = $file.name.split(".mkv")
$replace = $split[0] -Replace $split[0],($newdir + $i + ".mkv")

# Trim spaces and rename the file
$image_string = $file.fullname.ToString().Trim()
"$split[0] renamed to $replace"
Rename-Item "$image_string" "$replace"
$i++
}
}
}
}
# RUN SCRIPT
renameFiles
"SCRIPT FINISHED"

Re: rename tv show to file name with the following script

Posted: October 4th, 2014, 1:17 am
by phairplay
That's helpful thank you but I have both mkv and mp4s that go through the same issue