Page 1 of 1

move files as per their filenames

Posted: 04 Apr 2008 16:40
by prashob12
Hi,

I am new to this forum and i am terrible in using batch files

I have some XML files for e.g.

1079.xml
35781.xml
75022.xml
10000.xml

here i need to move xml files which has the file names greater or equal to 35781 to a particular folder namely "less" in the same directory.

Please help me in this

Regards
Prashob

Posted: 04 Apr 2008 23:06
by DosItHelp
prashob12,

This should work:
Open a command prompt and change to the directory where the XML files are. Then execute the following command:

Code: Select all

for %A in (*.xml) do @if %~nA GEQ 35781 move %A less


DOS IT HELP? :wink:

Posted: 07 Apr 2008 09:32
by prashob12
It works!!!

Here can you tell me how you used the commands.

And also from where can i know the batch file commands.

I right now have some batch file short cuts, but when come to using that it becomes confusing

Thanks a lot
Prashob

Posted: 07 Apr 2008 18:50
by DosItHelp
Sure:

for %A in (*.xml) do command %A

uses the %A variable to loop through all files that match the "*.xml" file pattern and calls "command %A" for each file that matches the, whereas "%A" will be substituted with the matching file.

@if %~nA GEQ 35781 command %A

the "@" sign prevents the "if" command (or any other command) to be echoed back to the console.

"%~nA" is like "%A" except it resolves to the filename only, without extension or path - this is your number.

"if" is the condition command used to compare if the filename is Greater or EQual the number. "command %A" is only be executed when the condition is true.

Help for "FOR" command here: http://www.dostips.com/DosCommandIndex.htm#FOR
or on command line run: FOR /?

Help for "IF" command here: http://www.dostips.com/DosCommandIndex.htm#IF
or on command line run: IF /?

Let me know what is most confusion so I can improve the site.

:wink: