1

I require a little help, I am new to creating Windows Bat files, I've done programming before, but this is new for me.

What I require is a .bat file to move the first xx Files based on the parameter I input in the current directory to a different directory, again I'm new to writing windows bat files I don't know the syntax, any help would appreciated

2
  • This is a good reference, with several example scripts.
    – AFH
    Commented Jul 24, 2018 at 11:36
  • This seems similar.
    – Sandeep
    Commented Jul 24, 2018 at 12:18

2 Answers 2

0

Parameters for batch files are referred to in the script as %1, %2 and so on. So the first argument you pass to the script you can access with %1.

e.g. C:\>test.bat Hello where the batch script is just:

@echo %1 pause

Will output "Hello"

With the rest of the script you'd need to be more specific on what you mean by first "xx" files. Sorted by date or name or some other attribute?

3
  • Ok, say I wanted to move a set of 250 files to another directory, sort them by name
    – Josh Adams
    Commented Jul 24, 2018 at 11:51
  • @JoshAdams - This site is not a free script writing service. You have enough information to work out what you need to do. If you run into problems with specific commands, then you can ask about them, but don't expect us to do all the work for you.
    – AFH
    Commented Jul 24, 2018 at 12:13
  • @JoshAdams AFH is right about not having the community here do all the work for you. But there are plenty example scripts out there to get you started. Found this tutorial post which pretty much does what you want and explains how it works in a few minutes of searching. All you have to do is set the limit to your variable and specify your directories and you're golden.
    – Gytis
    Commented Jul 24, 2018 at 13:48
0
    @echo off

set Source=C:\Users\Josh\documents
set Target=C:\Users\Josh\test

set MaxLimit=250

for /f "tokens=1* delims=[]" %%G in ('dir /A-D /B "%Source%\*.*" ^| find /v /n ""') do (
move "%Source%\%%~nxH" "%Target%"
if %%G==%MaxLimit% exit /b 0
)

After enough research I got this to do what I want to do.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .