DosTips.com

A Forum all about DOS Batch
It is currently 02 Dec 2016 18:19

All times are UTC-06:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 30 Oct 2013 14:41 
Offline
Expert

Joined: 04 Oct 2008 09:49
Posts: 357
My script launches action by routine ":MY-C" upon each file with a folder "W:\SpeedTest\" with this :-
Code: Select all
FOR %%f IN ("W:\SpeedTest\*.*") DO CALL :My-C "%%f" 

I am now into "brain fade" after debugging ":My-C" which is now working well.

Unfortunately the files are being processed in the wrong sequence.
I would like to process them in order of size -smallest file first, largest file last (though I could live with the opposite sequence)
Please tell me how to achieve this by fixing or replacing the the initial
Code: Select all
FOR %%f IN ("W:\SpeedTest\*.*") ...


Regards
Alan


Top
   
PostPosted: 30 Oct 2013 15:11 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 6033
Use something like this:

Code: Select all
pushd "W:\SpeedTest\"
for /f "delims=" %%f in (' dir /b /os /a-d ') do CALL :My-C "%%f"
popd


Top
   
PostPosted: 30 Oct 2013 17:23 
Offline
Expert

Joined: 04 Oct 2008 09:49
Posts: 357
Many Thanks - that is working.

I assume the double quotes at the start of ""W:\SpeedTest\" is a harmless typo,
It seems to have no effect on operation if I retain or delete the excess ".

There is one strange side-effect that puzzles me.

My originally code can restrict its selection of files with, for example, the mask *.bin
e.g.
Code: Select all
FOR %%f IN ("W:\SpeedTest\*.bin") DO CALL :My-C "%%f"

the code :My-C is invoked whilst its current directory is C:\ or whatever the script happened to be launched with.

Your code has the side effect that My-C is executed with W:\SpeedTest\ as its current directory.

This adaptation of your code works as well as your original, and has the same side effect
Code: Select all
pushd ""W:\SpeedTest\"
for /f "delims=" %%f in (' dir "W:\SpeedTest\*.bin" /b /os /a-d ') do CALL :My-C "%%f"
popd

By removing the pushd and popd I remove the side effect
Code: Select all
for /f "delims=" %%f in (' dir "W:\SpeedTest\*.bin" /b /os /a-d ') do CALL :My-C "%%f"

unfortunately this somehow causes :My-C to misbehave.

Is there a simple fix that avoids the need for pushd and popd ?
If not I can live with it.

Again, many thanks.

Regards
Alan


Top
   
PostPosted: 30 Oct 2013 21:25 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3364
Does this help you understand.
Code: Select all
@echo off
FOR %%f IN ("C:\SpeedTest\*.bin") DO echo %%f

for /f "delims=" %%f in ('dir "C:\SpeedTest\*.bin" /b /os /a-d') do echo %%f

for /f "delims=" %%f in ('dir "C:\SpeedTest\*.bin" /b /os /a-d') do echo %%~dpnxf

pause



Output
Code: Select all
C:\SpeedTest\1.bin
C:\SpeedTest\2.bin
C:\SpeedTest\3.bin
2.bin
3.bin
1.bin
C:\Users\Squashman\Desktop\2.bin
C:\Users\Squashman\Desktop\3.bin
C:\Users\Squashman\Desktop\1.bin


Top
   
PostPosted: 31 Oct 2013 01:04 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 6033
Good to see you back squashman.

I have to add that I get confused with %%~fa as it doesn't return the full path if you currently aren't in the folder. It returns the full path to the current folder.

Code: Select all
@echo off
for /f "delims=" %%f in (' dir "c:\files\*.jpg" /b /os /a-d ') do echo CALL :My-C "%%~ff"
pause


That above returns this, where the files are in c:\files folder:

CALL :My-C "d:\abc\28-10-2013 13-35-31.jpg"
CALL :My-C "d:\abc\keyboard with plate.jpg"
CALL :My-C "d:\abc\colo_1652_scan.jpg"
CALL :My-C "d:\abc\The Joke.jpg"
CALL :My-C "d:\abc\Swing.jpg"


But alan_b it can be worked around by using this, where you specify the path in two places.
Adding /s in the dir command is an option also if you don't have subdirectories in that folder.

Code: Select all
for /f "delims=" %%f in (' dir "W:\SpeedTest\*.bin" /b /os /a-d ') do CALL :My-C "W:\SpeedTest\%%~nxf"


Top
   
PostPosted: 31 Oct 2013 02:24 
Offline
Expert

Joined: 04 Oct 2008 09:49
Posts: 357
Between waking up and getting out of bed this morning I was embarrassed to realise my brain had gone to sleep before I posted my last question. :(
I really must try to get my body away from the keyboard and into bed first :)

However, thank you both for rushing to my aid.

Also thank you for the additional insights you have now given me.

Regards
Alan


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited