Detect and renaming the files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Q. April
Posts: 19
Joined: 27 Jan 2018 14:36
Location: Mayatopia

Detect and renaming the files

#1 Post by Q. April » 14 Apr 2018 13:23

Every week I downloaded mp4 files more than 200 episodes/series and many other types. such as .exe and .pdf .The original folder is the download folder,Now it have more than 100000 files including sub-folders(Because it is really tiring to rename and move the file one by one). Some of them i downloaded the same file multiple times because the old ones BURIED in lot of files and did not find them.

If this program is successful it would save my time for 1 year rather than doing it manually

I try to rename the files in a more precise name like :

(I did not put name clearly in the past,Because the average age here is old and not interested in it and now i have put it in order to make clearer)

Anime :

366 DC DOWNLOADNIME.mp4 to Detective Conan Episode 366.mp4
( Detect 'DC' and '367' )

JP-OP831ID-360p.mp4 to One piece Episode 831
( Detect 'OP' and '831' )

One-Piece-Episode-833.mp4 to One piece Episode 833
( Detect 'One-Piece' and '833' )

Notes:1. As you can see,Every original files has a different names patten ( Sometimes names behind numbers or vice versa )
2. ( JP-OP831ID-360p.mp4) and ( One-Piece-Episode-833) are the same anime.
3. ( 366 DC DOWNLOADNIME.mp4) I do not want " DOWNLOADNIME" because it's just information from the website.

Installer :

vlc-3.0.1-win32.exe to Vlc.exe
( Detect 'vlc' )

Firefox Installer.exe to Firefox.exe
( Detect 'Firefox' )

ChromeSetup.exe to Google Crome.exe
( Detect 'Chrome' )

Also i have over 100 other file types at same directory that i want to rename and move it by same method

I tried to look at their code but I did not understand it completely,
viewtopic.php?f=3&t=8465&p=56116&hilit= ... ile#p56116
viewtopic.php?f=3&t=8457&p=56081&hilit= ... ile#p56081
viewtopic.php?f=3&t=8457&p=56079&hilit= ... ile#p56079

Maybe The way it operates is:

1 :Detects file types ,
2 :Detects name and numbers(episode)
3 :Detects file categories ,
4 :rename the files
5 :move the files (For now it not important)



Most Commands/ways i did not know because i never used it

So far i have just:

Files Manager.bat

Code: Select all

:loop

::Detects_types

If %filetype% equ exe set "types=installer"
If %filetype% equ mp4 set "types=Anime"

goto names

:Name

::Anime

If %filename% equ DC set "filename=Detective Conan"
If %filename% equ OP set "filename=One Piece"
If %filename% equ One-Piece set "filename=One Piece"

::Installer 

If %filename% equ vlc set "Vlc"
If %filename% equ Chrome set "filename=Google Crome"
If %filename% equ Firefox set "filename=Firefox"

goto categories

:categories

::Anime
If %filename% equ Detective Conan set "categories=Anime"
If %filename% equ One Piece set "categories=Animes"

md Animes/One Piece
md Animes/Detective Conan

::Installer
If %filename% equ Vlc set "categories=Media"
If %filename% equ Firefox set "categories=Network Browser"
If %filename% equ Google Crome set "categories=Network Browser"

md Installer/Network Browser

if %categories% equ %Anime% ren %originalfile% %filename% Episode %Episode%.mp4 
if %types% equ %instaler% ren %originalfile% %filename%.exe 

goto loop
Notes 1. As you can see MD and REN comands will not work as expected as i am using 'spacing' to split the folder name and names.(i hope there is another way)
2. it just do process one file each loop (i know how to do it)
3.I do not know how to detects file names/types (real problem)


Output what i need from code above

1. Rename the file according to given setting

(For now i just want renaming it first ,about moving the files maybe i tried modify it myself later)
2. Move the file according to given setting

Anime files will move to the anime folder and move again by the anime name.
: Download/anime/One Piece/One piece Episode 833.mp4
:Download/anime/Detective Conan/Detective Conan Episode 366.mp4

Installer files will move to the Installer folder and move again by the Installer category.
: Download/Installer/Media/Firefox.exe
:Download/ Installer/Network Browser/Firefox.exe

Maybe i do not need full code, Which is more important i can learn and understanding every written code,Thanks.
Last edited by Q. April on 16 Apr 2018 05:59, edited 2 times in total.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Detect and renaming the files

#2 Post by penpen » 15 Apr 2018 03:37

Q. April wrote:
14 Apr 2018 13:23
I tried to look at their code but I did not understand it completely,
It would help us to help you, if you describe which point exactly you don't understand.

A guess is, that it has to do something with "for /F"-loops. In that case it might help you to read the for help ("for /?" command shell ("cmd.exe")).

penpen

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Detect and renaming the files

#3 Post by Aacini » 15 Apr 2018 04:45

Q. April wrote:
14 Apr 2018 13:23
can someone help me?
I invite you to carefully read the first post on this forum.

I also invite you to read this post.

After that, you may post a new description of your problem with full details because the current description cause many doubts. For example:

When a file is renamed from XXXXaaa0089.mp4 to "XXXXXX episode 997.mp4":
  • Where the six XXXXXX in new name come from? The original name have only four XXXX
  • How the new 997 is derived from old 0089?
Note that, as stated, the following command solve your problem:

Code: Select all

ren XXXXaaa0089.mp4 "XXXXXX episode 997.mp4"
Antonio

Q. April
Posts: 19
Joined: 27 Jan 2018 14:36
Location: Mayatopia

Re: Detect and renaming the files

#4 Post by Q. April » 16 Apr 2018 06:03

penpen said
It would help us to help you, if you describe which point exactly you don't understand.
I try to explain it

Aacini said
I invite you to carefully read the first post on this forum.
Thank you for inviting me,I do not know after editing it better,worse or over ......

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Detect and renaming the files

#5 Post by penpen » 16 Apr 2018 15:03

Q. April wrote:
14 Apr 2018 13:23
1. As you can see MD and REN comands will not work as expected as i am using 'spacing' to split the folder name and names.(i hope there is another way)
You should use doublequotes around the filenames:

Code: Select all

ren "a b c" "d e f"
Q. April wrote:
14 Apr 2018 13:23
3.I do not know how to detects file names/types (real problem)
I'm unsure what you mean with "detect filename".
The command line interpreter cannot read your mind, so he can only find, what you "serve him"; noone could guess that "DC" is short for "Detective Conan" (why not a short for "Da Capo" or others?).
You have to create patterns, which you can analyze.

Assumed that all Detective Conan Episodes have this format "<episode><whitespace>DC<whitespace><anything>.mp4",
and also assumed, that no other anime/application/whatever doesn't match that pattern,
then you could use:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
for %%a in ("* DC *.mp4") do (
	for /f "delims=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " %%b in ("%%~na") do (
		echo(Found Anime "Detective Conan" Epsiode "%%~b"
	)
)
Instead of the echo command you could do something different; but i think it's good to see a renaming list before renaming them.
If you echo the rename command (echo ren "a" "b"), then you could execute your batch file (assumed "Files Manager.bat") with redirected input from command shell ("cmd.exe"):

Code: Select all

"Files Manager.bat" > "result.bat"
So you could edit the resulting batch file befor executing it.

Same for any other pattern.


penpen

Edit: Corrected some typos.

Q. April
Posts: 19
Joined: 27 Jan 2018 14:36
Location: Mayatopia

Re: Detect and renaming the files

#6 Post by Q. April » 17 Apr 2018 13:31

Thanks :D :)

Q. April
Posts: 19
Joined: 27 Jan 2018 14:36
Location: Mayatopia

Re: Detect and renaming the files

#7 Post by Q. April » 25 Apr 2018 09:21

sorry ,when i trying to complete the program ,i found patterns not working perfectly ,

Code: Select all

@echo off
setlocal enableExtensions disableDelayed Expansion
for %%a in (""* DC *.mp4"") do (
	for /f "delims=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " %%b in ("%%~na") do (
		echo(Found Anime "Detective Conan" Epsiode "%%~b"
	)
)
(""* DC *.mp4"")wildcard not working as expected , it not only processing 366 DC DOWNLOADNIME.mp4 but the whole folder,( it really problem because it rename from xxxx.exe to xxxx Episode 366.exe)

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Detect and renaming the files

#8 Post by penpen » 25 Apr 2018 09:32

Sorry, i made two typos... which i have corrected above (but currently i'm surfing using my mobile phone, so i cannot test the result).
Hopefully it will work now.


penpen

Post Reply