Fellow Forum Members,
I have video files (avi, mpg, mp4, etc...) inside of folders. The Folder name is the actual name of the video (such as "Thomas Wedding Video scene 2") and the actual video file itself is named using a number such as "12345.avi". Is it possible for a script to perform the task of renaming the video file by using the Folder Name and once it's renamed with the Folder Name it moves the video file out of the folder and then deletes the folder it was originally contained within? Below is a small example:
BEFORE SCRIPT IS EXECUTED:
Folder Name = Thomas Wedding Video Scene 2
Video File Name = 12345.avi (actual footage of Thomas wedding)
AFTER SCRIPT IS EXECUTED:
Folder Name = No Longer Exists because Script deletes it
Video File Name = Renamed to "Thomas Wedding Video Scene 2.avi"
I need the script to perform this only for folders I select. Any help will be greatly appreciated.
Script for Removing Folders
-
highend
- Posts: 14942
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Script for Removing Folders
Code: Select all
$selectedFolders = get("SelectedItemsPathNames", "|");
foreach($item, $selectedFolders, "|") {
if (exists($item) == 2) {
$baseFolderName = gettoken($item, -1, "\");
$files = listfolder($item, "*", 1, "|");
foreach($file, $files, "|") {
$fileExt = getpathcomponent($file, "ext");
if ($file != "") {
renameitem("$baseFolderName", $file);
moveto "<curpath>", "<curpath>\$baseFolderName\$baseFolderName.$fileExt";
}
}
delete 1, 0, $item;
}
}folders, not files so I didn't include any further error checkings...
One of my scripts helped you out? Please donate via Paypal
-
binar
- Posts: 21
- Joined: 11 Aug 2013 05:32
Re: Script for Removing Folders
Highend,
Thanks for your post. I tested it out and attached you will see the error messages I got. To summarize, I created a "Test Master" folder. Within this folder there are three folders named Test1, Test2, and Test3. Within each of these folders there is a small AVI file named 12345.avi. If the script was working successfully I should see after execution three AVI files within the "Test Master" folder named:
Test1.avi
Test2.avi
Test3.avi
And the folders Test1, Test2, and Test3 should be moved into the Recycle Bin as empty folders no longer containing AVI files.
What the script is doing instead is moving all three Test1, Test2 and Test3 folders into the Recycle Bin. Each folder in the Recycle Bin still contains three AVI files. However they have been renamed Test1.avi, Test2.avi and Test3.avi. So it is successfully renaming the files using the containing Folder Name.
Is it possible to modify the code so that all three files renamed to Test1.avi, Test2.avi and Test3.avi remain located in the "Test Master Folder"? Furthermore, can the empty folders named Test1, Test2, and Test3 get moved to the Recycle Bin as empty folders? I would be very grateful if you or anyone in this forum can make this modification to the code. Thanks in advance.
Thanks for your post. I tested it out and attached you will see the error messages I got. To summarize, I created a "Test Master" folder. Within this folder there are three folders named Test1, Test2, and Test3. Within each of these folders there is a small AVI file named 12345.avi. If the script was working successfully I should see after execution three AVI files within the "Test Master" folder named:
Test1.avi
Test2.avi
Test3.avi
And the folders Test1, Test2, and Test3 should be moved into the Recycle Bin as empty folders no longer containing AVI files.
What the script is doing instead is moving all three Test1, Test2 and Test3 folders into the Recycle Bin. Each folder in the Recycle Bin still contains three AVI files. However they have been renamed Test1.avi, Test2.avi and Test3.avi. So it is successfully renaming the files using the containing Folder Name.
Is it possible to modify the code so that all three files renamed to Test1.avi, Test2.avi and Test3.avi remain located in the "Test Master Folder"? Furthermore, can the empty folders named Test1, Test2, and Test3 get moved to the Recycle Bin as empty folders? I would be very grateful if you or anyone in this forum can make this modification to the code. Thanks in advance.
To see the attached files, you need to log into the forum.
-
highend
- Posts: 14942
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Script for Removing Folders
Why don't you just select the folders that contain the files?
So instead of selecting the masterfolder that contains all subfolders, go into the masterfolder and select all sufolders that actually contain the files. You didn't mention in the first place that recursion will be used for more than one hierarchy so I didn't include that case. I don't have much time today to fix that...
So instead of selecting the masterfolder that contains all subfolders, go into the masterfolder and select all sufolders that actually contain the files. You didn't mention in the first place that recursion will be used for more than one hierarchy so I didn't include that case. I don't have much time today to fix that...
One of my scripts helped you out? Please donate via Paypal
-
yusef88
- Posts: 1148
- Joined: 28 Jan 2013 03:50
- Location: Windows 8.1 32-bit
Re: Script for Removing Folders
please,could you modify script to automatically add increment on collision nameshighend wrote:Code: Select all
$selectedFolders = get("SelectedItemsPathNames", "|"); foreach($item, $selectedFolders, "|") { if (exists($item) == 2) { $baseFolderName = gettoken($item, -1, "\"); $files = listfolder($item, "*", 1, "|"); foreach($file, $files, "|") { $fileExt = getpathcomponent($file, "ext"); if ($file != "") { renameitem("$baseFolderName", $file); moveto "<curpath>", "<curpath>\$baseFolderName\$baseFolderName.$fileExt"; } } delete 1, 0, $item; } }
-
binar
- Posts: 21
- Joined: 11 Aug 2013 05:32
Re: Script for Removing Folders
yusef88 and highend,
Thanks for your postings. Let me start from the beginning. I have close to 3,400 subfolders nested within a folder named Customer Footage. All 3,400 subfolders contain video clips I have collected over 15 years of operating a wedding video business. Right now I have to wait around 30 seconds for my Windows OS to refresh the main Customer Footage folder every time I exit any of the subfolders. I want to eliminate 30 seconds of waiting by deleting 3,400 subfolders and just have all video files no longer nested within subfolders.
My goal is to get a script to process all 3,400 so that it does the following:
I have tried both scripts, and both scripts move the subfolder and the video file within straight into the Recycle Bin. My question to anyone out there, Is it possible for a script to send all 3,400 subfolders straight to the Recycle Bin as empty subfolders? However, the same script needs to leave behind in the main root folder 3,400 video files that have been renamed using the subfolder names that are now located in the recycle bin? In other words, what I'm seeking for the script to do is to extract all 3,400 video files from each subfolder. Once this is accomplished all 3,400 empty subfolder need to go to the recycle bin. But not before each of the video file is renamed using the empty subfolder name.
Any help in developing such a script will be greatly appreciated. Thanks in advance.
Thanks for your postings. Let me start from the beginning. I have close to 3,400 subfolders nested within a folder named Customer Footage. All 3,400 subfolders contain video clips I have collected over 15 years of operating a wedding video business. Right now I have to wait around 30 seconds for my Windows OS to refresh the main Customer Footage folder every time I exit any of the subfolders. I want to eliminate 30 seconds of waiting by deleting 3,400 subfolders and just have all video files no longer nested within subfolders.
My goal is to get a script to process all 3,400 so that it does the following:
- The script needs to cut and paste the video file out of the subfolder while at the same time renaming it using the name of the subfolder.
Once the subfolder is empty of video file the script needs to move the subfolder to the Recycle Bin as an empty subfolder
I have tried both scripts, and both scripts move the subfolder and the video file within straight into the Recycle Bin. My question to anyone out there, Is it possible for a script to send all 3,400 subfolders straight to the Recycle Bin as empty subfolders? However, the same script needs to leave behind in the main root folder 3,400 video files that have been renamed using the subfolder names that are now located in the recycle bin? In other words, what I'm seeking for the script to do is to extract all 3,400 video files from each subfolder. Once this is accomplished all 3,400 empty subfolder need to go to the recycle bin. But not before each of the video file is renamed using the empty subfolder name.
Any help in developing such a script will be greatly appreciated. Thanks in advance.
-
highend
- Posts: 14942
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Script for Removing Folders
@yusef88
instead of the old renameitem line.
@binar
My script does what you want but only when you select the folders that contain the video files...
Regardless if it's 3400 folders or anything lower / higher. Just use ctrl + a to select them all and then use the script. It's a one time job...
Code: Select all
renameitem("$baseFolderName", $file, , "-01");@binar
My script does what you want but only when you select the folders that contain the video files...
Regardless if it's 3400 folders or anything lower / higher. Just use ctrl + a to select them all and then use the script. It's a one time job...
One of my scripts helped you out? Please donate via Paypal
-
binar
- Posts: 21
- Joined: 11 Aug 2013 05:32
Re: Script for Removing Folders
Highend,
Thanks for your last post. Below is the revised code I used that includes the change you told me to make:
I tested your revised code several times. I made sure to first select the folders I want the script to process.
It succeeds in the task of renaming the video file with the same name used by the folder it's nested within.
However, it still fails in the task on how it's handling the subfolder. The script is still sending the subfolder to the Recycle Bin with the video file still inside. What the script needs to do is send an empty subfolder to the Recycle Bin and not one with the renamed video file still inside. The video file needs to stay behind in the Root folder no longer nested within a subfolder since the empty subfolder it was once within ends up in the Recycle Bin through the magic of the script.
I'm using XYplorer version 11.30.0100. Could the problem be that your script works for you and not for me because we are using two different versions of XYplorer? Below is a screen capture of the Run Script Window I'm running your script from. I am still getting the same error dialog windows I posted in my second post. If you or anyone else following this thread can provide any help it will be greatly appreciated.
Thanks for your last post. Below is the revised code I used that includes the change you told me to make:
Code: Select all
$selectedFolders = get("SelectedItemsPathNames", "|");
foreach($item, $selectedFolders, "|") {
if (exists($item) == 2) {
$baseFolderName = gettoken($item, -1, "\");
$files = listfolder($item, "*", 1, "|");
foreach($file, $files, "|") {
$fileExt = getpathcomponent($file, "ext");
if ($file != "") {
renameitem("$baseFolderName", $file, , "-01");
moveto "<curpath>", "<curpath>\$baseFolderName\$baseFolderName.$fileExt";
}
}
delete 1, 0, $item;
}
}
It succeeds in the task of renaming the video file with the same name used by the folder it's nested within.
However, it still fails in the task on how it's handling the subfolder. The script is still sending the subfolder to the Recycle Bin with the video file still inside. What the script needs to do is send an empty subfolder to the Recycle Bin and not one with the renamed video file still inside. The video file needs to stay behind in the Root folder no longer nested within a subfolder since the empty subfolder it was once within ends up in the Recycle Bin through the magic of the script.
I'm using XYplorer version 11.30.0100. Could the problem be that your script works for you and not for me because we are using two different versions of XYplorer? Below is a screen capture of the Run Script Window I'm running your script from. I am still getting the same error dialog windows I posted in my second post. If you or anyone else following this thread can provide any help it will be greatly appreciated.
To see the attached files, you need to log into the forum.
-
highend
- Posts: 14942
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Script for Removing Folders
Code: Select all
$selectedFolders = get("SelectedItemsPathNames", "|");
setting "BackgroundFileOps", 0;
foreach($item, $selectedFolders, "|") {
if (exists($item) == 2) {
$baseFolderName = gettoken($item, -1, "\");
$files = listfolder($item, "*", 1, "|");
foreach($file, $files, "|") {
$fileExt = getpathcomponent($file, "ext");
if ($file != "") {
$newName = renameitem("$baseFolderName", $file);
moveto "<curpath>", $newName;
}
}
delete 1, 0, $item;
}
}- Used an easier way to determine the new name of a file that will be moved
One of my scripts helped you out? Please donate via Paypal
-
binar
- Posts: 21
- Joined: 11 Aug 2013 05:32
Re: Script for Removing Folders
Highend,
Your script is beyond the ultimate! It works flawlessly. I am amazed! Thanks a million for saving me from performing what was going to be a very tedious task.
Just to summarize. First, the three subfolders I selected automatically ended up in the Recycle Bin. In addition, I checked the folders in the Recycle Bin and all of them were empty of video files. Also the video files that were originally nested within each subfolder were renamed using the subfolder name and were left behind within the Root folder. They did not end up in the Recycle Bin. That is awesome.
If you don't mind, can you provide a brief summary of how your code works. I'm mainly interested in knowing about the logic your code follows and important commands it uses as well. I'm a newbie to this and would like to know what did you find to be the best reference material to learn how to write XYPlorer scripts?
Again, thanks a lot for solving the problem within this thread.
Your script is beyond the ultimate! It works flawlessly. I am amazed! Thanks a million for saving me from performing what was going to be a very tedious task.
Just to summarize. First, the three subfolders I selected automatically ended up in the Recycle Bin. In addition, I checked the folders in the Recycle Bin and all of them were empty of video files. Also the video files that were originally nested within each subfolder were renamed using the subfolder name and were left behind within the Root folder. They did not end up in the Recycle Bin. That is awesome.
If you don't mind, can you provide a brief summary of how your code works. I'm mainly interested in knowing about the logic your code follows and important commands it uses as well. I'm a newbie to this and would like to know what did you find to be the best reference material to learn how to write XYPlorer scripts?
Again, thanks a lot for solving the problem within this thread.
-
yusef88
- Posts: 1148
- Joined: 28 Jan 2013 03:50
- Location: Windows 8.1 32-bit
Re: Script for Removing Folders
same opinion thanks highendbinar wrote:Highend,
Your script is beyond the ultimate! It works flawlessly. I am amazed! Thanks a million for saving me from performing what was going to be a very tedious task.
XYplorer Beta Club