.bat move file to folder based on filename + remove string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
anarchoi
Posts: 1
Joined: 03 Oct 2015 12:49

.bat move file to folder based on filename + remove string

#1 Post by anarchoi » 03 Oct 2015 12:52

I have a folder with thousands of filenames like this. I need to put them inside folders and remove the useless parts from the filenames. I need to do this before adding the files inside my XBMC library.

[ www*.AnnoyingSpam.*com ] Some.File.Name.With.A.Very.Long.String.avi
[ www*.AnnoyingSpam.*com ] Another.File.With.A.Very.Long.String.mpg
[ www*.AnnoyingSpam.*com ] Again.And.Again.mp4

- First, I want to strip the AnnoyingSpam.com tags in the files
- Then, create a folder based on the file name without the tag and without the extension
- Finally, move the file to the new folder
- Repeat for the rest of the files in the root directory of the batch file


So far all I got is a script that will create folder and move files. But it adds the tag "Folder" to each folder and it doesn't remove the AnnoyingSpam.com tag

@echo off

for /f "usebackq delims=?" %%a in (`dir /a-d /b`) do (
if not "%%~dpnxa"=="%~dpnx0" call :func "%%~a"
)

goto :EOF

:func
set file=%~1
set dir=%file% Folder
md "%dir%" Folder 2>nul
move "%file%" "%dir%"
goto :EOF

So my question is how can i remove these strings from the folder names that are being created in the above script:

"[ http://www.AnnoyingSpam.com ]"

" Folder"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: .bat move file to folder based on filename + remove stri

#2 Post by foxidrive » 03 Oct 2015 21:38

Do any filenames have % or ! in them?

How many characters need to be removed from the start of the names?

See here: viewtopic.php?f=3&t=6108

Post Reply