Jump to content











Photo
- - - - -

Please help me to go ahead ?

cmd winpe boot.wim usb booting multibooting

  • Please log in to reply
147 replies to this topic

#26 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 22 July 2017 - 05:08 PM

Which "following" result? :unsure:

 

How §@ç#ing hard is it to understand that you need to first test only "snippets of code", understand how they work, if needed modify them, and only later assemble them together?

 

Change this.

robocopy "%USERDIR%\Music" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Music" /E /MT:1

to

SET USERDIR
SET USER
SET DATETIME
PAUSE
robocopy "%USERDIR%\Music" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Music" /E /MT:1

If you have undefined variables, maybe it is not so surprising that BOTH the source and target are messed up.

 

:duff:

Wonko



#27 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 22 July 2017 - 05:13 PM

Sorry...I forget to modify Source and destination path...



#28 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 22 July 2017 - 05:26 PM

Is post #25 not a test ?

NO, it isn't.

 

What cdob posted EXACTLY as he posted it in #20 is a valid snippet to be tested. (but still you need to implement it properly)

 

The snippets I posted on #14 are valid snippets to be tested, as they are.

 

They DO NOT attempt to blindly copy an unknown amount of data from an unknown source to an unknown target (you were lucky that robocopy threw an error).

 

You should have (provided that you have more than a single C: volume on the machine) a LIST of drives, actually first a list of ALL drives connected, later reduced to a reduced list of NTFS drives, in the case of cdob's snippet you should have more than one valid NTFS drive as long as the value you attribute to BACKUP_SIZE is not big enough to exclude all volumes but C:.

 

:duff:

Wonko



#29 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 22 July 2017 - 05:36 PM

I am still getting wrong Destination path ?

@echo off
setlocal EnableDelayedExpansion
set first=true
FOR /F "tokens=1-2* delims=\ " %%a in ('fsutil fsinfo drives ^| more') do (
  if not defined first set drive=%%a
  if defined first ( set drive=%%b &set first=)
  echo !drive!
  
  FOR /F "tokens=2 delims=:" %%f in ('fsutil volume diskfree !drive! ^| find "of free bytes" ') do @(
    set mb=%%f
    set mb=!mb:~,-3!
    set /A mb /= 1024 >nul
    echo !drive! !mb!
    if !mb! GTR 2000 set FREEDRIVE=!drive!& set FREEDRIVE
  )
)
ECHO %FREEDRIVE%
ECHO !FREEDRIVE!
mkdir "%FREEDRIVE%\BACKUP\Music"
echo robocopy "C:\Users\Anand\Music" "%FREEDRIVE%\BACKUP\Music" /E /MT:1
pause
robocopy "C:\Users\Anand\Music" "%FREEDRIVE%\BACKUP\Music" /E /MT:1
PAUSE

Result-

----------

C:
C:  2415
FREEDRIVE=C:
C:
C:
A subdirectory or file C: \BACKUP\Music already exists.
robocopy "C:\Users\Anand\Music" "C: \BACKUP\Music" /E /MT:1
Press any key to continue . . .

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : Saturday, July 22, 2017 11:05:36 PM
   Source : C:\Users\Anand\Music\
     Dest : C:\Data\ \BACKUP\Music\

    Files : *.*

  Options : *.* /S /E /DCOPY:DA /COPY:DAT /MT:1 /R:1000000 /W:30

------------------------------------------------------------------------------

        *EXTRA Dir        -1    C:\Data\ \BACKUP\Music\sandisk\
          *EXTRA File                504        C:\Data\ \BACKUP\Music\desktop.ini
          *EXTRA File             224747        C:\Data\ \BACKUP\Music\InstallWhim.png
          *EXTRA File              45025        C:\Data\ \BACKUP\Music\Legacy.gif
          *EXTRA File             147534        C:\Data\ \BACKUP\Music\Order Statement -  Confirmation of  eBay order (PaisaPay ID_43752825739).pdf
          *EXTRA File              76772        C:\Data\ \BACKUP\Music\Transaction Confirmation.pdf
          *EXTRA File               9251        C:\Data\ \BACKUP\Music\[ 01 ] Install Multiboot.txt
          *EXTRA File               2765        C:\Data\ \BACKUP\Music\[ 09 ] Set default boot for UEFI mode.txt

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         1         1         0         0         1
   Files :         2         0         2         0         0         7
   Bytes :    41.6 k         0    41.6 k         0         0   494.7 k
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : Saturday, July 22, 2017 11:05:36 PM

Press any key to continue . . .

It's looking %FREEDRIVE% is displaying "C: " instead of "C:" ? Why there is a SPACE just after C: ??

Am I still doing something wrong ?



#30 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 22 July 2017 - 05:45 PM

if defined first ( set drive=%%b &set first=)

It's looking cdob above line having an unwanted SPACE just before '&' ? It work if I use following code

if defined first ( set drive=%%b& set first=)

And if I use second one then everything just work as expected !!!

 

If I put 'BACKUP_SIZE=14000' *(E: have 96000 MB free), then cdob code does not work. My C: Drive have only 2300 MB space. 'cdob' code does not look for another Drives (E: ) ? Does it look only starting drive letter (C:) ?

 

Currently I am testing in Full Windows OS. But I will use it in WinPE10. So I will not consider X: ( %systemdrive% ) and Windows OS Drive (%SYSPART%) as Destination backup drive...So how I can skip these two Drive Letter ?

if !mb! GTR %BACKUP_SIZE% if not "%SYSPART%"=="%%d:" if not "%SystemDrive%"=="%%d:" set FREEDRIVE=%%d:& GOTO :DO_BACKUP

May be I should use something like this ? Does above code have any invalid syntax ?



#31 cdob

cdob

    Gold Member

  • Expert
  • 1469 posts

Posted 22 July 2017 - 07:53 PM

Unfortunately the fsutil output code is windows version specific, adjust to Window 10 yourself.
https://ss64.org/viewtopic.php?id=327

#32 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 22 July 2017 - 09:53 PM

@devdevadev

 

 

Why don' t you simply try to READ what is posted and FOLLOW the suggestions?

 

Can you simply run the two simple command lines proposed in post #24?

http://reboot.pro/to...ad/#entry204213

and post results?

 

Untill the output of fsutil fsinfo drives is not parsed correctly on your OS there is no sense to check/test anything else, as anything that comes after depends on that parsing.

 

In other words, FORGET about anything else and find a way (either parsing correctly the output of fsutil fsinfo drives or using any other method, mentioned in this thread or not mentioned in this thread, MOUNTVOL, DISKPART, whatever) to have a list of ALL drive letters assigned on the system.

 

Until you get that list, you cannot "go ahead".

 

:duff:

Wonko



#33 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 22 July 2017 - 10:50 PM

I don't know.

 

The issue with fsutil fsinfo drives is that it (at least on most OS) prints a 0x00 character after each drive letter, as cdob just explained.

 

Hence the workarounds, like 

fsutil fsinfo drives |find /v"" <- suggested by Wonko

or

fsutil fsinfo drives | more <- suggested by cdob

 

The plain output should be:

Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\

when one of the workarounds is used it should become:

 

Drives: C:\
D:\
E:\
F:\
G:\
H:\
I:\
J:\

 

Maybe on your (stupid) Windows 10 something has changed, it is up to you to find how it behaves.

 

:duff:

Wonko

I am getting same output for both cdob and Wonko workaround ?

Microsoft Windows [Version 10.0.16232.1000]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\Kdeva>fsutil fsinfo drives
Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ N:\

C:\Users\Kdeva>fsutil fsinfo drives |find /v""
Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ N:\

C:\Users\Kdeva>fsutil fsinfo drives | more
Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ N:\

C:\Users\Kdeva>FSUTIL FSINFO DRIVES | find ":"
Drives: C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ N:\ 

C:\Users\Kdeva>

AFAICS, ALL above workaround gives desirable result ? I don't see any differences so what should be reason for getting extra SPACE just after 'C:' ? Am I still not getting what you are suggesting to test ?

 

In which OS you are getting following output ?

Drives: C:\
D:\
E:\
F:\
G:\
H:\
I:\
J:\


#34 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 23 July 2017 - 12:08 PM

Good :), it means that on Windows 10 (at least in the version you are using) the good MS guys have corrected the stupid output that inserted the 0x00 (both XP and 7 were affected, hence most probably Vista also).
 
Then to get the list of drives (without the trailing backslash), then exclude non NTFS drives and finding the one with most free space this should do:
 


@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /F "tokens=* delims=" %%A in ('fsutil fsinfo drives') do CALL :Parse_drives %%A
SET ALLDrives
PAUSE

FOR %%A IN (%ALLDrives%) DO (
FOR /F "skip=2 tokens=2 delims=:" %%B IN ('fsutil volume diskfree %%A') DO (
ECHO %%A %%B
SET Vol_%%A=%%B
)
)

SET NTFSDrives=
FOR /F "tokens=2 delims=_=" %%A IN ('SET VOL_') DO SET NTFSDRIVES=!NTFSDrives! %%A

SET NTFSDRIVES
PAUSE

FOR %%A IN (%NTFSDrives%) DO CALL :Sort_val %%A !VOL_%%A!

FOR /F "tokens=2 Delims==" %%A IN ('SET Free_') DO SET MostFree=%%A

ECHO Drive with the most free space is drive %MostFree%
ECHO !VOL_%MostFree%!

GOTO :EOF


:Sort_val
SET Num=0000000000000%2
SET Num=%Num:~-14,14%
SET Free_%Num%=%1
GOTO :EOF 

:Parse_drives
SHIFT
SET AllDrives=%Alldrives% %1
IF NOT %2.==. GOTO :Parse_drives
SET AllDrives=%Alldrives::\=:%
GOTO :EOF
Try this and report.

:duff:
Wonko

#35 Zharif

Zharif

    Frequent Member

  • .script developer
  • 172 posts
  • Location:Germany
  •  
    Germany

Posted 23 July 2017 - 12:19 PM

...sorry for intruding.

 

@devdevadev,

The script below should also give you an idea on how to get variables for
- ready drives with file system NTFS
- their corresponding drive sizes sorted in ascending order
- drive with biggest free space
- user folders you provided
- directory size of user folders

Script has been tested under Win10Pro v.1703 as well as under XPSP3 and Win7Pro
in a virtual machine. Please note that selecting the user folders of a remote
system is a quite uncertain task if you don't know the exact folder names.
Anyway, an example is provided below.

One note:
Be careful to change the variable NAMES here (as well as in Wonkos provided scripts).
Doing so may result in broken values or maybe crashing of this script.
So, you should know what you're doing before trying to change the variable names.

Hope this script is a little bit of help

Edit: some comments

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
:: Set number of leading zeros to add
SET "_Iteration=14"

:: ============================================================================
:: Get list of ready/non-ready drives as well as if file system is NTFS
:: avoiding annoying beeps from win7 and above.
:: Usage of mountvol offers compatibility to windows xp.
:: From win7 and upwards you could use the fsutil "VOLUME LIST" command
:: to get a list of all available drives.
:: ============================================================================
FOR /F %%a in ('MOUNTVOL^|FIND ":\"^|SORT') DO (
FSUTIL FSINFO VOLUMEINFO %%a|FIND "NTFS" >NUL 2>&1 && SET "_DrvOK=!_DrvOK!%%a" && SET "_DrvOK_NTFS=!_DrvOK_NTFS!%%a"||SET "_DrvNReady=!_DrvNReady!%%a")
:: remove colon and bkslash from list entries
SET "_DrvOK=%_DrvOK::\= %"
SET _DrvOK_NTFS=%_DrvOK_NTFS::\= %
SET _DrvNReady=%_DrvNReady::\= %

:: ============================================================================
:: Get free space of drives in bytes.
:: For further use get the localised expression for "free".
:: It will be needed for "find" command to avoid localisation issues.
:: ============================================================================
FOR %%a IN (%_DrvOK_NTFS%) DO (
  FOR /F "tokens=3,5" %%b IN ('DIR %%a: /-C /-O /W') DO (set _VolFree_%%a=%%b& SET _SearchMask=%%c))

:: ============================================================================
:: reorder free space list - drive with biggest available byte size is last
:: ============================================================================
FOR %%a IN (%_DrvOK_NTFS%) DO (CALL :_PadZerosAndSort %%a !_VolFree_%%a!)

:: ============================================================================
:: set drive with biggest available byte size
:: ============================================================================
FOR /F "tokens=2 Delims==" %%a IN ('SET _VFree') DO (SET _VMostFree=%%a)

:: ============================================================================
:: Get user paths
:: ============================================================================
IF NOT DEFINED _UserPath SET "_UserPath=%HOMEDRIVE%%HOMEPATH%"
DIR "%_USERPATH%" /B >NUL 2>&1||ECHO User path not found ...exit here&&GOTO:_End

DIR "%_USERPATH%\Music" /B >NUL 2>&1 && ECHO Music found ...&&SET _User_Music=%_UserPath%\Music
DIR "%_USERPATH%\Video" /B >NUL 2>&1 && ECHO Video found ...&&SET _User_Video=%_UserPath%\Video
DIR "%_USERPATH%\Pictures" /B >NUL 2>&1 && ECHO Pictures found ...&&SET _User_Pictures=%_UserPath%\Pictures
DIR "%_USERPATH%\Desktop" /B >NUL 2>&1 && ECHO Desktop found ...&&SET _User_Desktop=%_UserPath%\Desktop
DIR "%_USERPATH%\Documents" /B >NUL 2>&1 && ECHO Documents found ...&&SET _User_Documents=%_UserPath%\Documents
DIR "%_USERPATH%\Downloads" /B >NUL 2>&1 && ECHO Downloads found ...&&SET _User_Downloads=%_UserPath%\Downloads

:: ============================================================================
:: Some output messages.
:: ============================================================================
ECHO _______________________________________________________________________________
ECHO.
ECHO Ready drives:          %_DrvOK%
ECHO Non-Ready drives:      %_DrvNReady%
ECHO.
ECHO Available NTFS drives: %_DrvOK_NTFS%
ECHO Biggest free space:    Drive %_VMostFree%:
FOR /F "tokens=2,3 Delims=_=" %%a IN ('SET _VolFree') DO (ECHO Free space on drive %%a: %%b bytes)
ECHO.
FOR /F "tokens=2* delims==" %%a in ('SET _User_') DO (ECHO User Pathes found: %%a)
ECHO _______________________________________________________________________________
ECHO.

:: ============================================================================
:: At least get folder sizes
:: Piping Dir to the Find command usually will let you get the last line of output.
:: To get the forelast line containing the directory size the /V switch of find is used.
:: Excluding lines that contain the searchmask -here localised string of "free" - 
:: will result in getting the desired forelast line.
:: ============================================================================
FOR /F "tokens=2* delims=_=" %%a in ('SET _User_') DO (
ECHO Determining and saving Directory size of %%a ...please wait
FOR /F "tokens=3" %%A IN ('DIR "%%b" /S /A /-C /-O /W^|FIND /V "%_SEARCHMASK%"') DO (SET _Size_User_%%a=%%A))
echo.
FOR /F "tokens=2,3* delims=_=" %%a in ('SET _Size_User_') DO (
ECHO Directory size of %%b: %%c bytes
)


:_End
CMD /K&EXIT

:_PadZerosAndSort
SET /A _Pos=%_Iteration%+1
:: ============================================================================
:: Environmental variables will be sorted automatically in ascending order.
:: Here, the entry with longest integer value will be placed at last position.
:: ============================================================================
FOR /L %%a IN (1,1,%_Iteration%) DO (CALL SET _Num=0%%_Num%%)
SET "_Num=%_Num%%2"
SET "_Num=!_Num:~-%_Pos%,%_Pos%!"
SET _VFree_%_Num%=%1
SET _Num=& SET "_Pos="
GOTO :EOF


  • devdevadev likes this

#36 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 23 July 2017 - 12:48 PM

@Zharif
 
A good example of making things more complex than needed, if I may :unsure:.
I mean, compare:
:Sort_val
SET Num=0000000000000%2
SET Num=%Num:~-14,14%
SET Free_%Num%=%1
GOTO :EOF
With:
...
SET "_Iteration=14"
...
:_PadZerosAndSort
SET /A _Pos=%_Iteration%+1
FOR /L %%a IN (1,1,%_Iteration%) DO (CALL SET _Num=0%%_Num%%)
SET "_Num=%_Num%%2"
SET "_Num=!_Num:~-%_Pos%,%_Pos%!"
SET _VFree_%_Num%=%1
SET _Num=& SET "_Pos="
GOTO :EOF
Don't they do the same thing? :dubbio:
 
A 14 digit number maxes out at 99999999999999, that is roughly 90 Tbytes, should be enough, and "padding in bulk" seems to me slightly more efficient than adding 00s one by one...
 
:duff:
Wonko

#37 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 23 July 2017 - 03:20 PM

Try this and report.

It works just fine as expected...

AllDrives= C: D: E: F: G: H: I: J: K: L: N:
Press any key to continue . . .
C:  2937581568
D:  1180704768
E:  117143306240
F:  1562435584
G:  111398912
H:  672976896
I:  4211609600
J:  250880
K:  10738040832
L:  20548096
NTFSDRIVES= C: D: E: F: G: H: I: J: K: L:
Press any key to continue . . .
Drive with the most free space is drive E:
 117143306240
Press any key to continue . . .

Can you provide !VOL_%MostFree%! in MB in your own style ?



#38 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 23 July 2017 - 03:55 PM

Now old script is also working as expected...

@echo off
pushd "%~dp0"
setlocal EnableDelayedExpansion

set SYSPART=
set SYSPART1=
FOR %%w IN (C D E F G H I J K L N M O P Q R S T U V W Y Z) DO (
if not defined SYSPART IF EXIST %%w:\Windows\explorer.exe set SYSPART=%%w:
if defined SYSPART IF EXIST %%w:\Windows\explorer.exe set SYSPART1=%%w:
)
set DATETIME=%DATE:~7,2%-%DATE:~4,2%-%DATE:~-4%_%TIME:~0,2%-%TIME:~3,2%-%TIME:~6,2%
set DATETIME=%DATETIME: =0%

CALL :START_BACKUP
PAUSE
EXIT

:START_BACKUP
SET USER=
SET USERDIR=
FOR /F %%A IN ('DIR "%SYSPART%\Users\" /B 2^>nul') DO (
if /i not "%%A"=="Public" FOR /F %%B IN ('DIR "%SYSPART%\Users\%%A\" /B 2^>nul ^|FIND /I "Desktop" ') DO (
IF EXIST "%SYSPART%\Users\%%A\Desktop" (
SET USER=%%A& SET USERDIR=%SYSPART%\Users\%%A
ECHO USER is !USER! and USER DIRECTORY is !USERDIR!
CALL :BACKUP_SIZE
CALL :FREEDRIVE
)
)
)
ECHO SMART BACKUP HAS BEEN DONE !!!
GOTO :EOF

:BACKUP_SIZE
SET BACKUP_SIZE=
FOR /F "tokens=1 delims=. " %%A in ('DIRUSE /M "%USERDIR%\Music" "%USERDIR%\Videos" "%USERDIR%\Desktop" "%USERDIR%\Documents" "%USERDIR%\Downloads"') DO SET BACKUP_SIZE=%%A
SET BACKUP_SIZE
GOTO :EOF

:FREEDRIVE
for /F "tokens=2-16 delims=:\ " %%A in ('fsutil fsinfo drives') do (
  for %%d in (%%A %%B %%C %%D %%E %%F %%G %%H %%I %%J %%K %%L %%M %%N %%O) do (
    for /F "tokens=2 delims=:" %%f in ('fsutil volume diskfree %%d: ^| find "of free bytes" ') do @(
      set mb=%%f
      set mb=!mb:~,-3!
      set /A mb /= 1024 >nul
      echo %%d: !mb!
      if !mb! GTR %BACKUP_SIZE% if not "%SYSPART%"=="%%d:" if not "%SYSPART1%"=="%%d:" if not "%SystemDrive%"=="%%d:" set FREEDRIVE=%%d:& GOTO :DO_BACKUP
    )
  )
)
Explorer ,
GOTO :EOF

:DO_BACKUP
echo FREEDRIVE IS %FREEDRIVE%
mkdir "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%" & Explorer.exe "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%"
robocopy "%USERDIR%\Music" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Music" /E /MT:1
robocopy "%USERDIR%\Videos" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Videos" /E /MT:1
robocopy "%USERDIR%\Desktop" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Desktop" /E /MT:1
robocopy "%USERDIR%\Pictures" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Pictures" /E /MT:1
robocopy "%USERDIR%\Documents" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Documents" /E /MT:1
robocopy "%USERDIR%\Downloads" "%FREEDRIVE%\BACKUP_%USER%_%DATETIME%\Downloads" /E /MT:1
GOTO :EOF

But I will prefer your method because I will not prefer Backup of different User folder to different partition. It will be better to copy all User backup files in same partition having greater free space...



#39 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 23 July 2017 - 03:57 PM

Can you provide !VOL_%MostFree%! in MB in your own style ?


In MB?
Add:

SET MostFreeMB=!VOL_%MostFree%!
SET MostFreeMb=%MostFreeMB: =%
SET MostFreeMb=%MostFreeMB:~0,-6%

ECHO Drive with the most free space is drive %MostFree% with %MostFreeMB% MB Free
Please understand how MB and MiB (NOT Men in Black ;)) are different units of measure:
https://en.wikipedia.org/wiki/Mebibyte
 
Since you use all tools that express size in bytes, it is fine to use MB (per definition, i.e. powers of 1000) as opposed to MiB (what should be used, powers of 1024 and that MS and most people, including myself, actually insist in calling MB), and of course truncating such a number (as opposed to rounding it) is actually safer in this usage case (of course it would be advisable to make sure that you have some "slack" space, i.e. once you have determined the size of what you are going to backup (that again makes NO SENSE to backup uncompressed) you should add a -say - 5-10% slack space (as any NTFS volume won't be particularly happy to run if filled up to the brim or however with less than 15% free). 
 
:duff:
Wonko

#40 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 23 July 2017 - 05:25 PM

I will use "slack" space of 1024 MB.

if %MostFreeMB% GTR 1024+%BACKUP_SIZE% if not "%SYSPART%"=="%MostFree%" if not "%SYSPART1%"=="%MostFree%" if not "%SystemDrive%"=="%MostFree%" set FREEDRIVE=%MostFree%& GOTO :DO_BACKUP

Suppose a partition of Internal hard disk (Suppose D:) having free space 96000 MB and connected NTFS Removable USB Drive *(say E:) also have free space of 96000 MB. So %MostFree% will be "E:' in your script ?? But It will be better if %MostFree% will be "D:" ?

 

Can I have following values ?

 

%MostFreeInternal%

%MostFreeExternal%

%MostFreeInternalMB%

%MostFreeInternalMB%



#41 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 23 July 2017 - 06:33 PM

Well, you can't invent syntax.
I doubt this will work:
if %MostFreeMB% GTR 1024+%BACKUP_SIZE%

And what I tried desperately to tell you is that you should make things as simple and as linear as possible :frusty:, you just wrote a 4 level deep IF condition.
The whole point is that is simpler to restrict the number of possible valid choices than allow all possible choice and AFTER one is chosen check if it is a valid one (and if it isn't you would need to provide a correspondent action).

You have ALLDRIVES?
You have a subset of them as NTFSDRIVES?
You want to make a subset of NTFSDRIVES excluding %SYSPART%.
And then a further subset excluding %SystemDrive%.
Then you want to make two further subsets one for External and one for Internal.

Now, how to decide if a disk is internal or external will be fun.

Maybe USB ones (via Registry) or via Diskpart:
http://reboot.pro/to...ve-in-diskpart/
are detectable, but - just saying - eSATA ones? :dubbio:

Maybe an external tool will be needed, like devcon or similar.

:duff:
Wonko
  • devdevadev likes this

#42 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 24 July 2017 - 01:51 PM

i want to use following LOGIC before doing backup

if %MostFreeIntMB% GEQ %BACKUP_SIZE% if not "%SYSPART%"=="%MostFreeInt%" if not "%SYSPART1%"=="%MostFreeInt%" if not "%SystemDrive%"=="%MostFreeInt%" set FREEDRIVE=%MostFreeInt%& GOTO :DO_BACKUP

if %MostFreeIntMB% LSS %BACKUP_SIZE% if %MostFreeExtMB% GEQ %BACKUP_SIZE% if not "%SystemDrive%"=="%MostFreeExt%" set FREEDRIVE=%MostFreeExt%& GOTO :DO_BACKUP

So I will need following variables

 

%MostFreeInt%

%MostFreeExt%

%MostFreeIntMB%

%MostFreeExtMB%



#43 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 24 July 2017 - 03:01 PM

i want to use following LOGIC before doing backup

That LOGIC is "wrong".

:duff:
Wonko



#44 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 24 July 2017 - 03:09 PM

That LOGIC is "wrong".

At which point it is wrong ?

 

In WinPE, %systemdrive% (X:) is Internal Disk or External Disk ? Is it RAMDRIVE ?

 

Should we not first list all Drive letters of Disk 0 (Internal Harddisk) for getting %MostFreeInt% and %MostFreeIntMB%

 

and All Drive Letters of Removable Drives to get %MostFreeExt% and %MostFreeExtMB% ??



#45 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 24 July 2017 - 03:55 PM

At which point it is wrong ?

 

In WinPE, %systemdrive% (X:) is Internal Disk or External Disk ? Is it RAMDRIVE ?

 

Should we not first list all Drive letters of Disk 0 (Internal Harddisk) for getting %MostFreeInt% and %MostFreeIntMB%

 

and All Drive Letters of Removable Drives to get %MostFreeExt% and %MostFreeExtMB% ??

Exactly in the point I tried to make on post #41:

http://reboot.pro/to...e-2#entry204238

 

If you don't understand something , it is OK if you ask for clarifications :), but insisting on the same thing, once you have been told why it is "wrong" (even if you don't understand the reason) it is not much productive.

It is extremely difficult to have a conversation with someone that simply ignores last reply. 

 

What is your goal? :dubbio:

 

You want to try to backup on a internal disk that is NOT ANY AMONG "%SYSPART%", "%SYSPART1%" "%SystemDrive%".

If that doesn't work, you want to try to backup to an external disk that is NOT "%SystemDrive%".

 

So, you don' t NEED to know how much space is free on ANY AMONG "%SYSPART%", "%SYSPART1%" "%SystemDrive%", as ALL these volumes are NOT suitable to receive the backup, NO MATTER how much free space they have.

 

Thus you REMOVE the NON SUITABLE drive letters BEFORE anything else (this will also result in shorter execution times as there will be less iterations of the loop.

 

Like:

SET ALLDrives=!Alldrives:%Syspart%=!

 

ALLDrives is now a list of ALL found Drive letters minus the Syspart one (that you cannot/don't want to use as backup target).

 

This way you don't need to check if the MostFree is %Syspart%, because the Mostfree is the most free among the drives excluded %Syspart%, so it CANNOT be %Syspart%.

 

:duff:

Wonko


  • devdevadev likes this

#46 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 24 July 2017 - 04:04 PM

Thus you REMOVE the NON SUITABLE drive letters BEFORE anything else (this will also result in shorter execution times as there will be less iterations of the loop.

 

Like:

SET ALLDrives=!Alldrives:%Syspart%!

 

ALLDrives is now a list of ALL found Drive letters minus the Syspart one (that you cannot/don't want to use as backup target).

 

This way you don't need to check if the MostFree is %Syspart%, because the Mostfree is the most free among the drives excluded %Syspart%, so it CANNOT be %Syspart%.

Thanks for the nice trick. Can we remove multiple Non SUITABLE drive letters *(%SYSPART%, %SYSPART1% and %systemdrive%) at once with above single line syntax ? Or I have to remove one by one in three lines ?



#47 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 24 July 2017 - 04:40 PM

SET ALLDrives=!Alldrives:%Syspart% =!

SET ALLDrives=!Alldrives:%Syspart1% =!

SET ALLDrives=!Alldrives:%SystemDrive% =!

 

Do you want to save one line with an excluded list, and a for loop?

 

Why not?

SET EXCLUDEDRIVES=%Syspart%  %Syspart1% %SystemDrive%

FOR %%A in (%EXCLUDEDRIVES%) DO SET ALLDrives=!Alldrives:%%A =!

 

Be careful with spaces, putting them in the substitution string may not get last drive letter in the list, and if you don't put it the ALLDrives variable will look "strange" having various spaces inside (but since it is only used for parsing in a CALL or FOR loop it should make no problem). 

 

 

 

:duff:

Wonko



#48 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 25 July 2017 - 07:13 PM

Now, how to decide if a disk is internal or external will be fun.

Maybe USB ones (via Registry) or via Diskpart:
http://reboot.pro/to...ve-in-diskpart/
are detectable, but - just saying - eSATA ones? :dubbio:

Maybe an external tool will be needed, like devcon or similar.

Can we not use 'fsutil' to get USBDRIVELETTERS ? And then minus USBDRIVELETTERS from ALLDRIVES to get Internal Disk Drive Letters ?

Which tool will be best in this situation ? Bootice ? Devcon ? MBRFix ? MBRWizard ?

May be we have to use a tool that will output USB Drive Letters in following manner or similar ?

Drives: G:\ H:\ M:\ O:\


#49 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 25 July 2017 - 07:36 PM

Can we not use 'fsutil' to get USBDRIVELETTERS ? And then minus USBDRIVELETTERS from ALLDRIVES to get Internal Disk Drive Letters ?

Which tool will be best in this situation ? Bootice ? Devcon ? MBRFix ? MBRWizard ?

Why not Diskpart ? :dubbio: (i.e.  what has been already suggested, that you just quoted and that you ignored as always)? :frusty:

 

You know, like:

 


Maybe USB ones (via Registry) or via Diskpart:
http://reboot.pro/to...ve-in-diskpart/
are detectable, but - just saying - eSATA ones? :dubbio:

 

 

 

:duff:

Wonko



#50 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 26 July 2017 - 04:02 AM

OK...That will be key point for the script. As a side learning, 

Microsoft DiskPart version 10.0.16232.1000

Copyright (C) Microsoft Corporation.
On computer: DESKTOP-DBET2DJ

DISKPART> LIST VOLUME

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     N                       DVD-ROM         0 B  No Media
  Volume 1         System Rese  NTFS   Partition    350 MB  Healthy    System
  Volume 2     C   Windows 10   NTFS   Partition     30 GB  Healthy    Boot
  Volume 3     H   Blast of Ma  NTFS   Partition    207 GB  Healthy
  Volume 4     F   OS           NTFS   Partition     40 GB  Healthy
  Volume 5     G   SMART PTN    NTFS   Partition     20 GB  Healthy
  Volume 6     D   WINDOWS      NTFS   Partition     50 GB  Healthy
  Volume 7     I   Blast of Ma  NTFS   Partition    415 GB  Healthy
  Volume 8     J   UEFI         FAT    Partition    504 KB  Healthy
  Volume 9                             Removable       0 B  No Media
  Volume 10                            Removable       0 B  No Media
  Volume 11    K   VANDITA      FAT32  Removable     10 GB  Healthy
  Volume 12    E   VANDITA      NTFS   Removable    109 GB  Healthy
  Volume 13    L   VANDITA      FAT    Removable     20 MB  Healthy

DISKPART>

Can we set two variable (Partition and Removable) containing Drive Letters in order of Volume Number with status 'Healthy' ?

 

    Partition :  C H F G D I J     ->>  MostFreePart : I

Removable :  K E L                  ->> MostFreeRem : E

 

Then we can get %MostFreePartMB% out of %Partition% and %MostFreeRemMB% out of %Removable% ?







Also tagged with one or more of these keywords: cmd, winpe, boot.wim, usb booting, multibooting

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users