Fsutil: batch file how to have a line that user can arrow up to paste to cmd line?

0

i have the below code which opens cmd and creates some sparse files using user entry to fill in some blanks. what i cant seem to do is to be able to have a line in the code that would be say C:\users\user name\desktop..what i want is to be able to easily insert this "C:\users\user name\desktop" then have the user fill in the "user name" section any ideas on how i would do this ? i tried to enter an echo and then user the arrow up command to copy the line down but that doesnt work so hoping you guys have something easier thanks

 @echo off
    :start
    COLOR 9B
    TITLE Batch File Creation
    echo ************************   
    echo * SPARSE FILE CREATION *        
    echo ************************
    echo Standard File Sizes:
    echo -  5mb = 5000000  bytes
    echo - 10mb = 10000000 bytes
    echo - 15mb = 15000000 bytes
    echo - 20mb = 20000000 bytes
    echo - File types can be any e.g. (xls, xlsx, jpg, png, doc, etc)  
    echo ************************
    echo.
    echo.
    echo.
    echo desktop path location is "c:\users\*your user name*\Desktop"
    set /p _path=Enter the file Path :
    set /p fname=Enter the Filename (e.g. test.xls) :
    set /p fsize=Enter the filesize (in Mb) :
    set /a sizeinbytes=fsize*1000*1000
    fsutil file createnew %_path%\%fname% %sizeinbytes%
    fsutil sparse setflag %_path%\%fname% 
    fsutil sparse setflag %_path%\%fname% 0 %sizeinbytes%
    echo %fname% File Created!!
    set /p _new=Would you like to create another file? [y]es, [n]o:
    If /i "%_new%"== "y" GOTO :start Else end

    end

Aaron Rice

Posted 2017-07-14T15:34:39.253

Reputation: 39

Answers

0

What I want is to be able to easily insert this "C:\users\user name\desktop"

then have the user fill in the "user name" section any ideas on how i would do this

You don't need to do this at all. The user profile is already available to you in the USERPROFILE environment variable:

> echo %userprofile%
C:\Users\DavidPostill

This is the profile path and it already contains the User Name for the current user.

So in your batch file, replace

echo desktop path location is "c:\users\*your user name*\Desktop"

With:

echo desktop path location is "c:\users\%userprofile%\Desktop"

Please read environment variables to see what other useful variables are already set for you.


DavidPostill

Posted 2017-07-14T15:34:39.253

Reputation: 118 938

thanks for that ..one more..can you pass the userprofile to the below line {fsutil file createnew %_path%\%fname% %sizeinbytes% so i can save time entering it manuall each time ? – Aaron Rice – 2017-07-14T17:31:53.993

Yes. Replace %_path%\%fname% with "c:\users\%userprofile%\Desktop\%fname%". Use " around the whole thing in case it contains spaces. Remove set /p _path=Enter the file Path : as you don't need it any more. – DavidPostill – 2017-07-14T17:38:14.987

0

Wouldn't this work?

set /p id="Enter Username: "
set location="C:\users\%id%\Desktop"
echo %location%

Unless I misunderstand your question.

Confuzing

Posted 2017-07-14T15:34:39.253

Reputation: 461