Ektron Find Replace Library Folder Names

| | | | |

This script will rename folder paths of renamed CMS folders.

SET XACT_ABORT ON

BEGIN TRAN

DECLARE @currtext NVARCHAR(255)
DECLARE @newtext NVARCHAR(255)
DECLARE @search NVARCHAR(500)
DECLARE @replace VARCHAR(500)
DECLARE @pos INT
DECLARE @id BIGINT
DECLARE @libtype_id INT

-- folder names
SET @search = '' --string to find
SET @replace = '' --replacement string

DECLARE curs CURSOR LOCAL FAST_FORWARD
FOR
SELECT folder_id
	,folder_name
	,libtype_id
FROM library_folder_tbl
WHERE folder_name LIKE '%' + @search + '%'

OPEN curs

FETCH NEXT
FROM curs
INTO @id
	,@currtext
	,@libtype_id

WHILE @@fetch_status = 0
BEGIN
	SET @newtext = replace(@currtext, @search, @replace)

	PRINT 'Changing ' + @currtext + ' to ' + @newtext

	UPDATE library_folder_tbl
	SET folder_name = @newtext
	WHERE folder_id = @id
		AND libtype_id = @libtype_id

	FETCH NEXT
	FROM curs
	INTO @id
		,@currtext
		,@libtype_id
END

CLOSE curs

DEALLOCATE curs

-- subfolder paths
SET @search = '' --string to find
SET @replace = '' --replacement string

DECLARE curs CURSOR LOCAL FAST_FORWARD
FOR
SELECT folder_id
	,subfolder
	,libtype_id
FROM library_folder_tbl
WHERE subfolder LIKE '%' + @search + '%'

OPEN curs

FETCH NEXT
FROM curs
INTO @id
	,@currtext
	,@libtype_id

WHILE @@fetch_status = 0
BEGIN
	SET @newtext = replace(@currtext, @search, @replace)

	PRINT 'Changing ' + @currtext + ' to ' + @newtext

	UPDATE library_folder_tbl
	SET subfolder = @newtext
	WHERE folder_id = @id
		AND libtype_id = @libtype_id

	FETCH NEXT
	FROM curs
	INTO @id
		,@currtext
		,@libtype_id
END

CLOSE curs

DEALLOCATE curs

--rollback tran
COMMIT TRAN

Source: http://www.skonet.com/Articles_Archive/Helpful_Sql_Scripts_for_Ektron_CMS_400_Net.aspx

Originally Posted on October 23, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.