View unanswered posts | View active topics It is currently 23 Oct 2014 07:04



Post new topic Reply to topic  [ 6 posts ] 
Help - How to process each target file in order of size ? 
Author Message
Expert

Joined: 04 Oct 2008 09:49
Posts: 357
Post Help - How to process each target file in order of size ?
My script launches action by routine ":MY-C" upon each file with a folder "W:\SpeedTest\" with this :-
Code:
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:
FOR %%f IN ("W:\SpeedTest\*.*") ...


Regards
Alan


30 Oct 2013 14:41
Profile

Joined: 10 Feb 2012 02:20
Posts: 4319
Post Re: Help - How to process each target file in order of size
Use something like this:

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


30 Oct 2013 15:11
Profile
Expert

Joined: 04 Oct 2008 09:49
Posts: 357
Post Re: Help - How to process each target file in order of size
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:
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:
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:
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


30 Oct 2013 17:23
Profile

Joined: 23 Dec 2011 13:59
Posts: 1935
Post Re: Help - How to process each target file in order of size
Does this help you understand.
Code:
@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:
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


30 Oct 2013 21:25
Profile

Joined: 10 Feb 2012 02:20
Posts: 4319
Post Re: Help - How to process each target file in order of size
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:
@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:
for /f "delims=" %%f in (' dir "W:\SpeedTest\*.bin" /b /os /a-d ') do CALL :My-C "W:\SpeedTest\%%~nxf"


31 Oct 2013 01:04
Profile
Expert

Joined: 04 Oct 2008 09:49
Posts: 357
Post Re: Help - How to process each target file in order of size
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


31 Oct 2013 02:24
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


Who is online

Users browsing this forum: Baidu [Spider], Yahoo [Bot] and 29 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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.