Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Batch file - move filename pieces

Name: Anonymous 2006-05-20 16:05

Hey guys,

Here's the problem I'm coding against: I download a lot of anime from various digisubbing groups, and they ALWAYS put their tag at the front of the file, so if you have some episodes from one team, and some eps from another, Windows will never sort them in a group, because the start of the filenames could be "[mahou]", "[AF-F]", "[wind]", etc... so even while looking at the directory with all my episodes in it, I have to do a file search to see if I have some episodes by another group, or read the name of every file I have.

I don't really care who subbed it more than what show it is, so I want to remove the tag from the front of the filename. Being a nice guy though, I want to keep it in the filename and just move it to the end instead of the front.

A task like this would be pretty simple in most serious, compiled languages, but I'm thinking there should be some way to do this in a DOS/Windows batch file? Does anyone know a way to do a letter-by-letter parsing of a filename, using [ and ] as sentinel characters?

I'm thinking I may even be able to do it sloppily by either putting everything from the start of the filename up to the first ']' into a variable, then somehow deleting it from the filename and reappending it. As an alternative, maybe I could scan each character and append each one to the contents of a variable until I hit ']'

Either way, I have no idea how to scan a filename with that level of granularity... can anyone point me in the right direction?

Thanks

Name: Anonymous 2006-05-20 17:51

use bash problem solved.

Name: Anonymous 2006-05-20 19:19

>>2
tens of thousands of problems gained

Name: Anonymous 2006-05-20 19:50

sounds like it'd be a huge pain to do with dos batch files, and very easy to do with perl regexing. i know neither, so have fun. besides which, why bother learning a new 'programming language' (dos batch files), when you could just use one you already know (c)?

seriously tho, i don't think it's easy to do regexing type stuff with batch files at all, i wouldn't even try.

Name: Anonymous 2006-05-20 20:25

>>4
I've been making batch files for a long time, and it's usually surprising what can be accomplished with some ingenuity. I also want to give this utility away, and have it useful to the most people I can.

If this doesn't work, I may try it in C++, but that language is a serious headache when it comes to debugging 2000 little hangups, improper type conversions, improper operators for a particular permuation of use, memory adressing issues, etc... I just don't have the will to try it.

I may just do it on VB.NET because I'm lazy, and it would work within 5 minutes, but then there would be the need for the .NET framework to run it, and the pointless RAM overhead from loading the CLRs when I just want a small simple app... still, it'd fill MY needs. I just thought it would be nice if I could release a nice small, easy to use, tweakable-by-anyone batch file to do it.

Name: Anonymous 2006-05-20 20:38

Use Perl (or rather Ruby, I haven't evaluated it on Windows though).

Name: Anonymous 2006-05-20 20:52

#!/usr/bin/perl

use Cwd;
$dir = getcwd;
opendir DIR,$dir or die "Unable to read contents of $dir\n";
while ($i = readdir(DIR)) {
    next if $i =~ /^\.\.?$/;
    next unless $i =~ /^\[(.+)\](.+)\.(.+)$/;
    $j = "$2 [$1]\.$3";
    $j =~ s/_/ /gi;
    print "Renaming: $i -> $j\n";
    rename("$dir/$i","$dir/$j") or die "Unable to rename $i\n";
}
closedir DIR;

Name: Anonymous 2006-05-21 13:04

FREEBASIC FTW

Name: Anonymous 2010-06-07 6:38

Hi, I can spam /prog/ too, you faggot.

Also, smoke weed everyday.

Name: ​​​​​​​​​​ 2010-09-08 16:06

Name: Anonymous 2010-11-14 21:08

Name: Anonymous 2011-02-02 23:46

Name: Sgt.Kabu곒뻿kiman讇㽔 2012-05-28 18:57

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List