Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Orbiter SDK Orbiter software developers post your questions and answers about the SDK, the API interface, LUA, meshing, etc.

Reply
 
Thread Tools
Old 10-08-2017, 02:02 PM   #1
fort
Orbinaut
Default Searching for a solution with a DOS batch code

Hello,

Working on nightlights.

I try to move, in DOS (with windows XP and a * .bat) - from a root folder - a set of files to subfolders that the batch creates simultaneously, and to which it assigns names in relation to file numbering.

A series of files named a_1.bmp, b_1.bmp, c_1.bmp, ... will be moved to a subfolder named 1.
A series of files named a_2.bmp, b_2.bmp, c_2.bmp, ... will be moved to a subfolder named 2.
A series of files named a_myfile.bmp, b_myfile.bmp, c_myfile.bmp, ... could be moved to a subfolder named myfile.

Some files might have names as: a_001396.bmp, b_001396.bmp..etc. And the corresponding subfolders named 001396, 001 397 ...

I found a code template ( and made some change for my use ) that might be appropriate ... (in French...)
https://openclassrooms.com/forum/suj...n-des-fichiers

... but I stumble on an obstacle:

beyond ..._9.bmp, and starting from _1.bmp, the script no longer creates subfolders.

Starting from ..._10.bmp or more, it works.

But I have no choice, at first sight, but to start from ..._1.bmp.

Not even ..._01.bmp

Attachment for testing.

If someone have an idea.



And thank you.


Edit: I'm quite a great beginner in DOS.
Attached Files
File Type: zip Dispatch.zip (98.0 KB, 3 views)

Last edited by fort; 10-08-2017 at 02:12 PM.
fort is offline   Reply With Quote
Old 10-08-2017, 03:43 PM   #2
kuddel
Donator
Default

Hi fort,
you're using the * (wildcard) a little bit wrong.
The * matches one ore more characters,
The ? matches exactly one character.
So changing the copy-line to this should work:
Code:
move /Y  "?_!disp!.bmp" "!disp!"


---------- Post added at 17:43 ---------- Previous post was at 17:35 ----------

Another thing is, that you could check for the existence of the (sub-)directory with 'if not exists' before executing 'MD'. So you don't have to "silence" error output (>NUL 1>&2)
Code:
@echo off
setlocal enabledelayedexpansion
for %%i in (*.bmp) do (
    for /F "tokens=2 delims=._" %%j in ('echo %%i') do (
        set disp=%%j
        if not exist !disp! MD !disp!
        move /Y "?_!disp!.bmp" "!disp!"
    )
)
pause
kuddel is offline   Reply With Quote
Thanked by:
Old 10-08-2017, 04:03 PM   #3
fort
Orbinaut
Default

Hello kuddel

I resumed after taking a break of a few weeks this summer my activity with the nightlights and this ends.

All my batch are pretty much at the point. But if I sometimes spent a lot of time on some ( I'm quite inexperienced, not far from a zero level ), I really did not see how to get around that one. I was even looking in the meantime for a substitution script to get around the difficulty but with an extra operation and quite a bit of research again.

Your script is impeccable.



Thank you and...thank you and...thank you.

( i'll try to understand your changes: this could be usefull for others implementations )


Edit:

Quote:
Originally Posted by kuddel View Post
 you're using the * (wildcard) a little bit wrong.
The * matches one ore more characters,
The ? matches exactly one character.
I did not think about that. I read here or there that it was equivalent. And according to the context ...

I really tried for several hours to change the settings, different combinations, even preview here or there for example that a space (disp=%% j or disp= %% j) could change the behavior of the script, but I was down.


Last edited by fort; 10-08-2017 at 04:29 PM.
fort is offline   Reply With Quote
Old 10-08-2017, 09:16 PM   #4
kuddel
Donator
Default

...yeah, DOS batch scripts have a high potential to drive one nuts , so don't feel bad.
My experience is just the result of many many many failures and dead-ends, too.
kuddel is offline   Reply With Quote
Thanked by:
Old 03-31-2018, 06:29 PM   #5
fort
Orbinaut
Default

Hello,

I have a problem with this script again. It works well for files named 1_1.bmp, 1_2.bmp ... 1_50.bmp ... 2_1.bmp, 2_2.bmp ... 2_50.bmp ... and creates as expected folders '1' '2' ... '50' ...; and simultaneously puts 1_1, 2_1 ... in the folder '1'; 1_2, 2_2 ... in folder '2'; 1_50 ... in the folder '50' ...

Now, it happens that my files may have to be named: OSM_1_1.bmp or ITO_1_1.bmp... ... so, longer names, but I search for an identical result (folders '1' '2'. .. '50' with files of the same last number in).
And there, it does not work anymore.

I searched on the internet for these questions of 'tokens' and 'delims' and some others things, but I am down. I do not see.

I think that
... tokens should be now =3 and delims=._" %%k or %%j %%k
( for /F "tokens=2 delims=._" %%j )
... set disp= %%k...
( set disp=%%j )
... but there:
"?_!disp!.bmp"
???

I can work around the problem with an additive script but if I could do with this one alone ...( there are already so many operations to do elsewhere for this work )

Again two attachments:

1 the initial device with "short name files".
2 the same but with "long name files", as above, but that does not work.

Good day
Attached Files
File Type: zip Short_names.zip (98.0 KB, 0 views)
File Type: zip Long_names.zip (98.1 KB, 1 views)

Last edited by fort; 04-01-2018 at 05:37 AM.
fort is offline   Reply With Quote
Reply

  Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 05:11 PM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright 2007 - 2017, Orbiter-Forum.com. All rights reserved.