Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to move .txt file so avi and txt has the same names
#1

1. I would like to say hello to everyone, because it is my first post :)

2. Some people are watching a lot of movies with subtitles. On example me :P Sometimes downloaded from some sites .txt file doesn't have the same name like ours .avi file. It's tiring to change these names in any gui application or even in console(usually there is a lot of other files like .rar, .r01...etc with similiar names). So I wrote this very little bash script which does that.



Code:
#!/bin/bash mv *.txt $(basename *.avi .avi).txt




It will work only if in present dir is only one .txt and .avi file, and if these files names doesn't insist any spaces. I didn't know how to make it working with spaces. If anyone know, please let me know.

I hope it may be usefull for someone :]

Reply
#2

A slight modification, to allow you to specify the file and you can actually use a pure bash method (rather than with basename) and do:



Code:
#!/bin/bash if [ $# -ne 2 ]; then echo "usage: $0 <file.txt> <file.avi>" >&2 exit 1 fi mv "$1" "${2%avi}txt"




Using *.avi, might lead to issues if you have multiple avi files in the one directory. Also note the quotes, to ensure spaces are still fine!

 

Sexy first post none the less ;)

Reply
#3

Thanks for help with this script. I actually always have one .txt and one .avi file (example below), and it is hard to type full name of txt file and avi file, because there are a lot of *.r?? files with similiar names. But that's in my case :]



Code:
orenji-the.4400.403.r00 orenji-the.4400.403.r01 orenji-the.4400.403.r02 orenji-the.4400.403.r03 orenji-the.4400.403.r04 orenji-the.4400.403.r05 orenji-the.4400.403.r06 orenji-the.4400.403.r07 orenji-the.4400.403.r08 orenji-the.4400.403.r09 orenji-the.4400.403.r10 orenji-the.4400.403.r11 orenji-the.4400.403.r12 orenji-the.4400.403.r13 orenji-the.4400.403.r14 orenji-the.4400.403.r15 orenji-the.4400.403.r16 orenji-the.4400.403.r17 orenji-the.4400.403.rar orenji-the.4400.403.sfv Sample the.4400.pl.4x03.txt the.4400.s04e03.dsr.xvid-orenji.avi the.4400.s04e03.dsr.xvid-orenji.nfo




I'd use a lot of TAB's and I'd have to look really close for every dots, numbers and other things in the names ;P

I'm going to try to improve my script witch quotes. It didn't work for me before :P But maybe this time I do this right.

Thanks again :]

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)