Computing.Net > Forums > Programming > Numerical order in batch/cmd

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Numerical order in batch/cmd

Reply to Message Icon

Name: pball
Date: September 4, 2008 at 15:58:43 Pacific
OS: XP Pro
CPU/Ram: 2.8 ghz / 2 gig
Product: home made
Comment:

I made a script that will process numbered files in a folder. I am aware of this "problem" i'm gonna explain.

When it runs it uses a for loop to process each file separately. So it starts with file 1 then 10,11,12,13,etc then moves on to 2,20,21

Is there a way to override this so it counts 1,2,3,4,etc

It isn't vital to what I'm doing but it would be nice to have them done in order.

here is my script

for /f "tokens=*" %%x in ('dir /b *.vob') do (
echo %%x
"F:\Encoding\Programs\megui\tools\dgindex\DGIndex.exe" -AIF=[%%~nx.vob] -IA=7 -TN=80,81 -OM=1 -OF=[%%~nx] -hide -exit
)

FYI it extracts audio from vob files and makes an avs script and dv2 project file. I'm batch encoding a dvd here.



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: September 4, 2008 at 16:55:38 Pacific
Reply:

I know this may not be possible(or convenient), but leading zero's on the first 9 files may help.


0

Response Number 2
Name: pball
Date: September 4, 2008 at 17:34:59 Pacific
Reply:

That could work for future use.

another mostly unrelated question I have also is there a way to remove quotes and file extensions from a full file name?

I have a set /p var=
then i drag a file onto the batch window and the location and name of the file are entered. The problem is if there are spaces in the location/name there are quotes when it's entered, if there are no spaces there are no quotes.

how can i remove the quotes if present and file extension?

so "F:\hey you\text.txt" would be F:\hey you\text

and F:\hey\text2.txt would be F:\hey\text2


0

Response Number 3
Name: Judago
Date: September 4, 2008 at 18:28:59 Pacific
Reply:

The below has a couple of limitations. Firstly if a file is not supposed to have a extension but a dot 4 or 5 characters in (depending on if it had quotes or not) it will be trimmed off. Var has to be defined to clear the second line as I couldn't get it to take quotes on the outside.


if not defined var goto :eof
if [^%var:~0,1%]==[^"] set var=%var:~1,-1%
if "%var:~-4,1%"=="." set var=%var:~0,-4%


0

Response Number 4
Name: pball
Date: September 4, 2008 at 19:36:30 Pacific
Reply:

Thanks Judago

That works perfectly and I don't see any problem with it. My files have nice name and 3 digit ext names.

Guess that's the end of this thread. I love quickly resolved threads, even though one is just playing the system


0

Response Number 5
Name: Mechanix2Go
Date: September 5, 2008 at 01:36:38 Pacific
Reply:

'dir /b *.vob'

Not obvious how that would give ANY ordering. But I'll stay tuned.


=====================================
If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: Judago
Date: September 5, 2008 at 02:16:34 Pacific
Reply:

"'dir /b *.vob'

Not obvious how that would give ANY ordering. But I'll stay tuned."

The dir command always seems sort it's output 0-9/a-z by default unless another sort order is specified (/o), the fact that *.vob is specified means that it will only output files that end in .vob in a sorted order.

This is just my experience though, I don't know if it's the same everywhere.


0

Response Number 7
Name: pball
Date: September 5, 2008 at 03:44:26 Pacific
Reply:

well i looked up that /o thing for the dir command. Lets you sort by name, ext, date, etc but when you choose alphabetical order it still uses that screwy 1,10,11,12 type of counting.


0

Response Number 8
Name: Mechanix2Go
Date: September 5, 2008 at 04:04:39 Pacific
Reply:

"The dir command always seems sort it's output 0-9/a-z by default unless another sort order is specified"

Not in my experience.

A sample

dir/b *.txt

rose-bud.txt
5191766.txt
bladeless.txt
amazon.txt
klint.txt
roseb.txt
PEG-prof.txt
24HRgold.TXT


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 9
Name: Judago
Date: September 5, 2008 at 16:02:16 Pacific
Reply:

Mechanix2Go,
Come to think of if your probably right, what I *should* have said is this is my experience with windows xp.

Would you belive I was trying to be cautious about making a broad and uninformed statment? I really nailed that one........


0

Response Number 10
Name: pball
Date: September 5, 2008 at 20:00:18 Pacific
Reply:

Hey I have a completely unrelated question to hijack my thread with.

Is there a way to make a long line in a batch script break to a new line?

For example:
"F:\Encoding\Programs\megui\tools\x264\x264.exe" --pass 1 --bitrate 700 --stats ".stats" --keyint 240 --min-keyint 24

that is about half of that line, is there a way to split it between lines (like wordwrap) and still have it all run? I don't want to have to scroll way over to see to whole line.

also wouldn't be a way to make a warning or something pop up when you try to close a batch program while it's running, don't wanna be able to accidentally close out of a script that takes a while to run


0

Response Number 11
Name: Judago
Date: September 9, 2008 at 02:32:00 Pacific
Reply:

I'm not entirely sure how to do either of these things, as such.

You could hide your window with nircmd, cmdow or something similar, then no one could close your window accidentally.

I did read something here about using hex 0a for something along the lines you asking but didn't get it to work(Only spent a couple of minutes on it).


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Numerical order in batch/cmd

Comparison of strings in batch file www.computing.net/answers/programming/comparison-of-strings-in-batch-file/15556.html

help in batch file www.computing.net/answers/programming/help-in-batch-file/10878.html

VB 6 Ascending numerical order code www.computing.net/answers/programming/vb-6-ascending-numerical-order-code/12251.html