Create batch file that sees whether file exists and if not exits

if exist "%BackupPath%\%programName%\*_%date:~4,2%%date:~7,2%%date:~12,2%.zip" (
if not exist "%BackupPath%\%programName%\*_%date:~4,2%%date:~7,2%%date:~12,2%.zip" (
echo x=messagebox(zip file with latest date not avaialble)
) else (
goto :EOF
)
)

what will be the issue in the code??

poup up echo message not coming prperly.
bhavani vAsked:
Who is Participating?
 
NVITConnect With a Mentor Commented:
This works.
Adjust BackupPath and programName to your needs.
I moved the filename date pattern to a variable FName to ease maintenance.

@echo off
setlocal enabledelayedexpansion

set BackupPath=C:\local\test
set programName=EE
set FName=*_%date:~4,2%%date:~7,2%%date:~12,2%.zip

if exist "%BackupPath%\%programName%\%FName%" (
	echo It's here! %fname%
) else (
	echo x=messagebox(zip file with latest date not avaialble)
	goto :EOF
)

Open in new window

0
 
KimputerCommented:
Is this partial code of the batch file, or FULL code?

If FULL, you're obviously missing all the variables.
2
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
I suspect this is pseudo-code we've all been dealing with in several open Qs by Bhavani V.

If he could be more forthcoming in answering Qs and keeping scope creep to a minimum it would be helpful.

Hell is he would listen to the repeated attempts people have made to get him to use [ code ] [ /code ] tags it would be helpful.

I mean this code obviously seems to be Pseudo-code:

messagebox(zip file with latest date not available)

Open in new window


I'm guessing he's thinking of "Net SEND" which is no longer functional.

the functionality could be duplicated to some extent a number of ways.

I prefer using straight CMD so something like this:

START "Zip file with latest date not available" /WAIT "cmd /K MODE CON COLS=45 LINES=10&CLS&ECHO.&ECHO.&ECHO.============================================&ECHO.  Zip file with latest date not available!&ECHO.&PAUSE&exit /b"

Open in new window


However, it could be done using Powershell calls or VBScript too.

We need Bhavani V. to work with us to properly scope and break apart his needs into a set of Qs designed to help him understand and create his total script, OR he needs to work with us to create the entire thing end to end in one go as a Gig (or, I guess, a single all-encompassing question, since Gigs went bye bye :(  RIP Gigs :( )
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Although, having been on some of his other Qs I'm fairly sure this will do the needful:

@(
	SETLOCAL ENABLEDELAYEDEXPANSION
	ECHO OFF
	SET "_eLvl=0"
	SET "_BackupPath=C:\Your\Path"
	CALL :GetDate
	SET "_FileGlob=*_!_YearMonthDay!.zip"
	SET "_FullGlob=!_BackupPath!\!_FileGlob!"
)

CALL :Main

(
	ENDLOCAL
	EXIT /B %_eLvl%
)

:Main
	IF NOT EXIST "%_FullGlob%" (
		ECHO.File Not Found!  Exiting Once pop-up is cleared...
		START "Zip file with latest date not available" /WAIT "cmd /K MODE CON COLS=45 LINES=10&CLS&ECHO.&ECHO.&ECHO.============================================&ECHO.  Zip file with latest date not available!&ECHO.&PAUSE&exit /b"
		SET "_eLvl=1"
		GOTO :EOF
	) 

	ECHO.  Your code continues here.

GOTO :EOF

:GetDate
	FOR /F "Tokens=1-3 delims=MTWFSmtwfsouehrandit:-\/. " %%A IN ("%DATE%") DO (
		FOR /F "Tokens=2-4 Skip=1 Delims=(-)" %%a IN ('ECHO.^| DATE') DO (
			SET "%%~a=%%~A"
			SET "%%~b=%%~B"
			SET "%%~c=%%~C"
			SET /a "#%%~a=1%%~A - (2%%~A-1%%~A)"
			SET /a "#%%~b=1%%~B - (2%%~B-1%%~B)"
			SET /a "#%%~c=1%%~C - (2%%~C-1%%~C)"
		)
	)
	SET "_YearMonthDay=%yy%%mm%%dd%"
GOTO :EOF

Open in new window

0
 
bhavani vAuthor Commented:
how to check the files are available in the folder or not?

i used *.* but its not working. files are not at all available but the remaining process are continuing.
 any other options are ter to check it?


  setlocal EnableDelayedExpansion & time /T
  Date /T
 
  IF EXIST "%ProgramPath%\%programName%\%dateFile%\*.*" (
  ECHO "LATEST FOLDER IS CREATED ..........PROCESS IS STARTED......."
  GOTO :1
  ) ELSE (
  ECHO "LATEST FOLDER NOT CREATED.... CREATE FOLDER AND START PROCESSING!!"
  PAUSE
  EXIT /B
  )
:1
Mkdir "%BackupPath%\%programName%\%date:~4,2%%date:~7,2%%date:~12,2%"
for /d %%A in ("%ProgramPath%\%programName%\%dateFile%\*.*") do (
    copy "%%~A\*.zip" "%BackupPath%\%programName%\%dateFile%"
      )
0
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Bhavi,

  It would behoove you to read the responses and reply to them instead of continually posting additional questions.

 I know you have been repeatedly told to use [ code ]  [/code ] tags and the like, and giving may questions which are not answered by you.

 I suspect you are not a native English speaker, perhaps you can tell us what your native language is?

If you explain this, then perhaps we can find another expert who might be kind enough to assist us in translating these messages between us.

What is your native language?

Ben
0
 
bhavani vAuthor Commented:
hi,

i got it what you guys are saying to attach the code file. i tried i dont know its correct or not. now i attaching check it out. native language is Tamil but i can understand English as well sir.

how to check the files are available in the folder ? i used *.* but its not working.
actually my  files are not available inside the folder but its processing remaining process as well. kindly help me to check the files in code
attached.txt
0
 
KimputerCommented:
Seems you didn't read a lot of the messages again.
Even the first message you missed. I already told you, you were missing variables. Then the next message is about how you should fill in the variables. And then, you just ignored it.
If you ignore all or some messages, you will get nowhere.
1
 
bhavani vAuthor Commented:
Oops sorry again.. i attached the code again. now its possible to check  my question?
attached.txt
0
 
KimputerCommented:
Remove all "echo off" in the code, run again, show us output.
That's because batch file dates depends on system display settings, which is different on every system (could be d/M/y or mm-dd-yyyy whichever is preferred by the user, thereby sometimes creating a folder with / as a character)
Changing it to VBscript would be nicer (and make the script more readable).
0
 
bhavani vAuthor Commented:
office system settings date only i used in the code. so no issue in that. sorry i need in .bat file for office purpose.
0
 
KimputerCommented:
You just started NOT READING AND LISTENING again. I told you before you will get nowhere if you do that.
I need the OUTPUT, as the DATE SETTINGS of YOUR PC or SERVER AFFECTS THE BATCH FILE OUTPUT and actually CAN'T CREATE FOLDERS if a "/" character is used.
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.