Delete last 12 characters of file names in external hard drive folder.

S.H.A.D.O.

Well-known Member
Joined
Sep 6, 2005
Messages
1,915
Good afternoon,

I have an external hard drive with a folder named MP4. Within that folder there are about 500 MP4 files. What I would like to do is to delete the last twelve characters from EACH of the filenames. The 12 characters are firstly a SPACE, then followed by [abcwdefgh] for example including the brackets, the 12 characters are IDENTICAL at the end of EACH file though. Is there an easy way to do this please without the need to edit every single one?.

Thanks in advance.
 
Thanks for another reply wigi,

I used the filename Toy Story (2013) - aaap bbbbbb xccc [ddddddddd] and run the above code.
After running the code it left me with Toy Story (2013) instead of Toy Story (2013) - aaap bbbbbb xccc.
I hope this makes sense.
I basically just want the LAST 12 characters of every filename deleted, the file names are different lengths if that makes a difference, but I always want the last 12 characters deleted because they are the same 12 characters in EVERY filename.

Thanks.
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I am very sorry, but with only 1 text file in the specified directory
Toy Story (2013) - aaap bbbbbb xccc [ddddddddd].txt

it changes the filename to:

Toy Story (2013) - aaap bbbbbb xccc.txt
 
Upvote 0
Also, with the code in #9 that you posted (in fact, my earlier code), it just works fine. Do you test in a correct way?
The only thing that I change is the directory (I have no F:\) and then run the code on the said .txt file.
 
Upvote 0
OK wigi,

Thanks for your time and effort, I appreciate it. I am only interested in mp4 files within thedirectory and folder anyway. I tried running your original code and it still loses some of the characters before the 12 characters, so at times it deletes maybe 15 or 20 characters.
Not to worry though, I will have a play around with it and see what I can come up with.
Thanks again and enjoy the rest of your Sunday.
 
Upvote 0
Hello


Again, I'd be happy to test more if you give me concrete examples of what goes wrong.
If you only want to treat mp4 files, you can indicate it in the Dir function: fn = Dir(sPath & "*.mp4")

2 remarks:
- you're using my revised code, aren't you?
- every filename has at least 12 characters before it reaches the extension .mp4 ?
 
Upvote 0
Hi wigi,

Yes, I am using your revised code.
Yes, every filename has at least 12 characters.

In the actual filenames there is NOT .mp4 at the end. The filenames are in the field NAME.

Thanks again.
 
Upvote 0
Hi...

Did you try the code I posted on the first page of this Thread?
 
Upvote 0
S.H.A.D.O.;3893460In the actual filenames there is NOT [B said:
.mp4[/B] at the end. The filenames are in the field NAME.

Still, I cannot find a case where it does not work. I am awaiting your filenames that lead to wrong results.

Also, please test apo's code, and provide feedback.
 
Upvote 0
Hi..

Also.. what do you mean exactly by this?

In the actual filenames there is NOT .mp4 at the end. The filenames are in the field NAME.

I am thinking you probably just have the Option ticked that syas to Hide file extensions for known filetypes in the Folder Options..?

Either way.. my code it still works perfectly when i test my code with the Toy Story string filename you posted above.
 
Upvote 0
Hi apo,

Thanks very much, it works perfectly. I must have missed your post somehow yesterday, it was pretty mad here though. I like the way it makes sure that you use the correct directory and folder, very neat indeed.
Thanks wigi for your time and effort.
I appreciate everyones time and effort to resolve this, thanks.
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,826
Members
449,190
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top