move files as per their filenames

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
prashob12
Posts: 7
Joined: 04 Apr 2008 16:26

move files as per their filenames

#1 Post by prashob12 » 04 Apr 2008 16:40

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

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 04 Apr 2008 23:06

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:

prashob12
Posts: 7
Joined: 04 Apr 2008 16:26

#3 Post by prashob12 » 07 Apr 2008 09:32

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

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#4 Post by DosItHelp » 07 Apr 2008 18:50

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:

Post Reply