You are not logged in.

#1 13 Apr 2014 14:42

vendor
Member
Registered: 13 Apr 2014
Posts: 5

Can I create different files with looping ?

hello smile

I want to create a different file in the folder with the function for, i've tried :


for /l %a in (1,1,10) do fsutil file createnew %random%.bat

but instead i get this :

image.png

Offline

#2 13 Apr 2014 14:49

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Can I create different files with looping ?

The issue can be worked around several ways. 
It occurs because %random% is parsed only when the loop is started - so it remains fixed at one value within the loop.

In the way you are using it this will work, but it can still fail on a file because the %random% variable can duplicate the same value in any given series of numbers.

@echo off
for /L %%a in (1,1,10) do call fsutil file createnew %%random%%.bat 100
pause

Last edited by foxidrive (13 Apr 2014 14:51)

Offline

#3 13 Apr 2014 15:15

vendor
Member
Registered: 13 Apr 2014
Posts: 5

Re: Can I create different files with looping ?

foxidrive wrote:

The issue can be worked around several ways. 
It occurs because %random% is parsed only when the loop is started - so it remains fixed at one value within the loop.

In the way you are using it this will work, but it can still fail on a file because the %random% variable can duplicate the same value in any given series of numbers.

@echo off
for /L %%a in (1,1,10) do call fsutil file createnew %%random%%.bat 100
pause

wow, it work smile
by the way, Can I write the code directly from cmd ?

thanks before big_smile

Offline

Board footer

Powered by