| 1. |
Solve : MS Dos Project? |
|
Answer» The project I have to do is create a zip file in MS Doc for all data that fails. & Then plainly put the created code with the rest of the code. Please tell me if I am on the right track & please give me hints. Sorry that I commented my code the way I did. I am used to dealing with C++ Programming & Java. Basically the program/ code is supposed to place all failed data into a file, I want to put it into a zip file. I am trying to figure out how to create the code so that the failed data can transfer into the zip file efficiently. P.S. I am doing this my uncle; who owns technology company. since every line with a // is now invalid you can start by fixing the comments. use REM, not ::, by the way. :: has too many special cases where it can cause all sorts of problems.Okay I fixed the comment aspect. Whats next?? Fixed Code: ECHO OFF :: Displays messages, or turns command-echoing off. set ConfigFile=config.cfg :: Allows you to change one variable or string to another. set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt :: Allows you to change one variable or string to another. set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt :: Allows you to change one variable or string to another. set wmailto=c:\windows\wmailto.exe :: Allows you to change one variable or string to another. set "ExistFreeSpace=0" :: Allows you to change one variable or string to another. echo Job starting.... >> %loglocation% :: Displays messages, or turns command-echoing on date /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. :: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% :: Call to the file and displays. :: ** Call MDMcreateCSVfiles :: Call to the file and displays. :: ** echo Returned from bat file call - continuing.... >> %loglocation% :: Keep file running after it returns :: ***Check if config file is there if not exist %ConfigFile% ( echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation% %wmailto% -t%loglocation% %email% "-s Config file is missing" goto :eof) :: Checks to see if file is there; if not display the following messages. :: *** Call the subroutine; :: Calls another batch file and then returns to current batch file to continue. :: *** first argument: the name of the var in the config file to look for :: *** second argument: the batch variable that should have the value assigned. call :ReadConfig TotalDirs TotalNo :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig email email :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig Warningemail Warningemail :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig extension extension :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig MinFreeSpacePrcnt MinFreeSpace :: Calls another batch file and then returns to current batch file to continue. echo Log space on server.... >> %loglocation% :: Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace >> %loglocation% :: Calls another batch file and then returns to current batch file to continue. setlocal EnableDelayedExpansion :: Inserts strings into the command environment. The set values can be used later by programs. FOR /L %%i IN (1,1,%TotalNo%) DO ( SET ind=%%i :: Executable statement call :ReadConfig Source!ind! source :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig OlderThan!ind! olderthan ::Calls another batch file and then returns to current batch file to continue. echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation% cd %source% :: Displays messages, or turns command-echoing off/on. echo . >>%loglocation% :: Displays messages, or turns command-echoing off/on. ::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% ::executable statement echo Starting delete... >> %loglocation% FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% ::Displays messages, or turns command-echoing off/on. echo Delete finished... >> %loglocation% :: Displays messages, or turns command-echoing off/on. echo. >>%loglocation% ) :: Displays messages, or turns command-echoing off/on. echo. :: Displays messages, or turns command-echoing off/on. echo All Deletes complete.... >> %loglocation% :: Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace>> %loglocation% :: Calls another batch file and then returns to current batch file to continue. date /t >> %loglocation% ::Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. echo >>%loglocation% :: Displays file. if %ExistFreeSpace% leq %MinFreeSpace% ( echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation% %wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server" ) :: Executable statement %wmailto% -t%loglocation% %email% "-s Files deleted on MDM server" goto :eof ::Executable statements :: **** Subroutines start here; no changes below this line ****** :ReadConfig for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a goto :eof :: Executable statements :FreeSpace @SETLOCAL ENABLEDELAYEDEXPANSION :: Allows you to change one variable or string to another. ::@SETLOCAL ENABLEEXTENSIONS :: Allows you to change one variable or string to another. @CLS // @FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p // @SET /A TotalSpace=!TotalBytes:~0,-9! // Allows you to change one variable or string to another. @SET /A FreeSpace=!FreeBytes:~0,-10! // Allows you to change one variable or string to another. @SET /A TotalUsed=%TotalSpace% - %FreeSpace% // Allows you to change one variable or string to another. @SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! // Allows you to change one variable or string to another. @SET /A PercentFree=100-!PercentUsed! // Allows you to change one variable or string to another. @ECHO Total space: %TotalSpace%GB // Displays messages @ECHO Free space: %FreeSpace%GB // Displays messages @ECHO Used space: %TotalUsed%GB // Displays messages @ECHO Percent Used: %PercentUsed%%% // Displays messages @ECHO Percent Free: %PercentFree%%% // Displays messages ::ENDLOCAL // ENDLOCAL &set "%~1=%PercentFree%" // goto :eof // First, most of the comments are still "//" second, they can only appear on a line by themselves. batch has no PROVISION for inline comments. I did it, whats next : ECHO OFF :: Displays messages, or turns command-echoing off. set ConfigFile=config.cfg :: Allows you to change one variable or string to another. set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt :: Allows you to change one variable or string to another. set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt :: Allows you to change one variable or string to another. set wmailto=c:\windows\wmailto.exe :: Allows you to change one variable or string to another. set "ExistFreeSpace=0" :: Allows you to change one variable or string to another. echo Job starting.... >> %loglocation% :: Displays messages, or turns command-echoing on date /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. :: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% :: Call to the file and displays. :: ** Call MDMcreateCSVfiles :: Call to the file and displays. :: ** echo Returned from bat file call - continuing.... >> %loglocation% :: Keep file running after it returns :: ***Check if config file is there if not exist %ConfigFile% ( echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation% %wmailto% -t%loglocation% %email% "-s Config file is missing" goto :eof) :: Checks to see if file is there; if not display the following messages. :: *** Call the subroutine; :: Calls another batch file and then returns to current batch file to continue. :: *** first argument: the name of the var in the config file to look for :: *** second argument: the batch variable that should have the value assigned. call :ReadConfig TotalDirs TotalNo :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig email email :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig Warningemail Warningemail :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig extension extension :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig MinFreeSpacePrcnt MinFreeSpace :: Calls another batch file and then returns to current batch file to continue. echo Log space on server.... >> %loglocation% :: Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace >> %loglocation% :: Calls another batch file and then returns to current batch file to continue. setlocal EnableDelayedExpansion :: Inserts strings into the command environment. The set values can be used later by programs. FOR /L %%i IN (1,1,%TotalNo%) DO ( SET ind=%%i :: Executable statement call :ReadConfig Source!ind! source :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig OlderThan!ind! olderthan ::Calls another batch file and then returns to current batch file to continue. echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation% cd %source% :: Displays messages, or turns command-echoing off/on. echo . >>%loglocation% :: Displays messages, or turns command-echoing off/on. ::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% ::executable statement echo Starting delete... >> %loglocation% FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% ::Displays messages, or turns command-echoing off/on. echo Delete finished... >> %loglocation% :: Displays messages, or turns command-echoing off/on. echo. >>%loglocation% ) :: Displays messages, or turns command-echoing off/on. echo. :: Displays messages, or turns command-echoing off/on. echo All Deletes complete.... >> %loglocation% :: Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace>> %loglocation% :: Calls another batch file and then returns to current batch file to continue. date /t >> %loglocation% ::Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. echo >>%loglocation% :: Displays file. if %ExistFreeSpace% leq %MinFreeSpace% ( echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation% %wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server" ) :: Executable statement %wmailto% -t%loglocation% %email% "-s Files deleted on MDM server" goto :eof ::Executable statements :: **** Subroutines start here; no changes below this line ****** :ReadConfig for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a goto :eof :: Executable statements :FreeSpace @SETLOCAL ENABLEDELAYEDEXPANSION :: Allows you to change one variable or string to another. ::@SETLOCAL ENABLEEXTENSIONS :: Allows you to change one variable or string to another. @CLS :: @FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p :: @SET /A TotalSpace=!TotalBytes:~0,-9! :: Allows you to change one variable or string to another. @SET /A FreeSpace=!FreeBytes:~0,-10! :: Allows you to change one variable or string to another. @SET /A TotalUsed=%TotalSpace% - %FreeSpace% :: Allows you to change one variable or string to another. @SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! :: Allows you to change one variable or string to another. @SET /A PercentFree=100-!PercentUsed! :: Allows you to change one variable or string to another. @ECHO Total space: %TotalSpace%GB :: Displays messages @ECHO Free space: %FreeSpace%GB ::Displays messages @ECHO Used space: %TotalUsed%GB :: Displays messages @ECHO Percent Used: %PercentUsed%%% :: Displays messages @ECHO Percent Free: %PercentFree%%% :: Displays messages ::ENDLOCAL :: ENDLOCAL &set "%~1=%PercentFree%" :: goto :eof :: Just to make sure you get this through: Quote from: BC_Programmer on June 10, 2010, 08:21:18 AM batch has no provision for inline comments. So, echo Job starting.... >> %loglocation% :: Displays messages, or turns command-echoing on needs to become: echo Job starting.... >> %loglocation% rem Displays messages, or turns command-echoing on You have been told this already... don't use double colons ( for comments! Use rem or REM. Using a broken LABEL (that is what :: is) causes problems in parenthetical structures, is unsupported, deprecated and is FROWNED UPON. ECHO OFF REM Displays messages, or turns command-echoing off. set ConfigFile=config.cfg REM Allows you to change one variable or string to another. set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt REM Allows you to change one variable or string to another. set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt REM Allows you to change one variable or string to another. set wmailto=c:\windows\wmailto.exe REM Allows you to change one variable or string to another. set "ExistFreeSpace=0" REM Allows you to change one variable or string to another. echo Job starting.... >> %loglocation% REM Displays messages, or turns command-echoing on date /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it. :: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% REM Call to the file and displays. :: ** Call MDMcreateCSVfiles REM Call to the file and displays. :: ** echo Returned from bat file call - continuing.... >> %loglocation% REM Keep file running after it returns :: ***Check if config file is there if not exist %ConfigFile% ( echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation% %wmailto% -t%loglocation% %email% "-s Config file is missing" goto :eof) REM Checks to see if file is there; if not display the following messages. :: *** Call the subroutine; REM Calls another batch file and then returns to current batch file to continue. :: *** first argument: the name of the var in the config file to look for :: *** second argument: the batch variable that should have the value assigned. call :ReadConfig TotalDirs TotalNo REM Calls another batch file and then returns to current batch file to continue. call :ReadConfig email email REM Calls another batch file and then returns to current batch file to continue. call :ReadConfig Warningemail Warningemail REM Calls another batch file and then returns to current batch file to continue. call :ReadConfig extension extension REM Calls another batch file and then returns to current batch file to continue. call :ReadConfig MinFreeSpacePrcnt MinFreeSpace REM Calls another batch file and then returns to current batch file to continue. echo Log space on server.... >> %loglocation% REM Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace >> %loglocation% REM Calls another batch file and then returns to current batch file to continue. setlocal EnableDelayedExpansion REM Inserts strings into the command environment. The set values can be used later by programs. FOR /L %%i IN (1,1,%TotalNo%) DO ( SET ind=%%i REM Executable statement call :ReadConfig Source!ind! source REM Calls another batch file and then returns to current batch file to continue. call :ReadConfig OlderThan!ind! olderthan REMCalls another batch file and then returns to current batch file to continue. echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation% cd %source% REM Displays messages, or turns command-echoing off/on. echo . >>%loglocation% REM Displays messages, or turns command-echoing off/on. ::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% REM executable statement echo Starting delete... >> %loglocation% FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% REM Displays messages, or turns command-echoing off/on. echo Delete finished... >> %loglocation% REM Displays messages, or turns command-echoing off/on. echo. >>%loglocation% ) REM Displays messages, or turns command-echoing off/on. echo. :: Displays messages, or turns command-echoing off/on. echo All Deletes complete.... >> %loglocation% REM Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace>> %loglocation% REM Calls another batch file and then returns to current batch file to continue. date /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it. echo >>%loglocation% REM Displays file. if %ExistFreeSpace% leq %MinFreeSpace% ( echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation% %wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server" ) REM Executable statement %wmailto% -t%loglocation% %email% "-s Files deleted on MDM server" goto :eof REM Executable statements :: **** Subroutines start here; no changes below this line ****** :ReadConfig for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a goto :eof REM Executable statements :FreeSpace @SETLOCAL ENABLEDELAYEDEXPANSION REM Allows you to change one variable or string to another. ::@SETLOCAL ENABLEEXTENSIONS REM Allows you to change one variable or string to another. @CLS REM @FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p REM @SET /A TotalSpace=!TotalBytes:~0,-9! REM Allows you to change one variable or string to another. @SET /A FreeSpace=!FreeBytes:~0,-10! REM Allows you to change one variable or string to another. @SET /A TotalUsed=%TotalSpace% - %FreeSpace% REM Allows you to change one variable or string to another. @SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! REM Allows you to change one variable or string to another. @SET /A PercentFree=100-!PercentUsed! REM Allows you to change one variable or string to another. @ECHO Total space: %TotalSpace%GB REM Displays messages @ECHO Free space: %FreeSpace%GB REM Displays messages @ECHO Used space: %TotalUsed%GB REM Displays messages @ECHO Percent Used: %PercentUsed%%% REM Displays messages @ECHO Percent Free: %PercentFree%%% REM Displays messages ::ENDLOCAL :: ENDLOCAL &set "%~1=%PercentFree%" REM goto :eof REM Now can someone please tell me how to create a zip file using this code? Thanks! Quote set ConfigFile=config.cfg REM Allows you to change one variable or string to another. You have also been told that you can't have inline comments! Don't you read the answers? Your configfile variable is going to be "config.cfg REM Allows you to change one variable or string to another." All those CHARACTERS. What are all those lines starting :: ** ? You are not going the right way to get your batch file fixed. ECHO OFF set ConfigFile=config.cfg set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt set wmailto=c:\windows\wmailto.exe set "ExistFreeSpace=0" echo Job starting.... >> %loglocation% date /t >> %loglocation% time /t >> %loglocation% :: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% :: ** Call MDMcreateCSVfiles :: ** echo Returned from bat file call - continuing.... >> %loglocation% :: ***Check if config file is there if not exist %ConfigFile% ( echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation% %wmailto% -t%loglocation% %email% "-s Config file is missing" goto :eof ) :: *** Call the subroutine; :: *** first argument: the name of the var in the config file to look for :: *** second argument: the batch variable that should have the value assigned. call :ReadConfig TotalDirs TotalNo call :ReadConfig email email call :ReadConfig Warningemail Warningemail call :ReadConfig extension extension call :ReadConfig MinFreeSpacePrcnt MinFreeSpace echo Log space on server.... >> %loglocation% call :FreeSpace ExistFreeSpace >> %loglocation% setlocal EnableDelayedExpansion FOR /L %%i IN (1,1,%TotalNo%) DO ( SET ind=%%i call :ReadConfig Source!ind! source call :ReadConfig OlderThan!ind! olderthan echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation% cd %source% echo . >>%loglocation% ::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% echo Starting delete... >> %loglocation% FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% echo Delete finished... >> %loglocation% echo. >>%loglocation% ) echo. echo All Deletes complete.... >> %loglocation% call :FreeSpace ExistFreeSpace>> %loglocation% date /t >> %loglocation% time /t >> %loglocation% echo >>%loglocation% if %ExistFreeSpace% leq %MinFreeSpace% ( echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation% %wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server" ) %wmailto% -t%loglocation% %email% "-s Files deleted on MDM server" goto :eof :: **** Subroutines start here; no changes below this line ****** :ReadConfig for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a goto :eof :FreeSpace @SETLOCAL ENABLEDELAYEDEXPANSION ::@SETLOCAL ENABLEEXTENSIONS @CLS @FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p @SET /A TotalSpace=!TotalBytes:~0,-9! @SET /A FreeSpace=!FreeBytes:~0,-10! @SET /A TotalUsed=%TotalSpace% - %FreeSpace% @SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! @SET /A PercentFree=100-!PercentUsed! @ECHO Total space: %TotalSpace%GB @ECHO Free space: %FreeSpace%GB @ECHO Used space: %TotalUsed%GB @ECHO Percent Used: %PercentUsed%%% @ECHO Percent Free: %PercentFree%%% ::ENDLOCAL ENDLOCAL &set "%~1=%PercentFree%" goto :eof Here it is! Please help me correct this. Replace the Code: [Select]:: *** with Code: [Select]REM. Sorry Patio, just had to..He's now been told 3 times... methinks this is going to go nowhere... No problem MacDad... |
|