Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch script not function as expected.

Posted on 2009-07-06
3
Medium Priority
?
408 Views
Last Modified: 2012-05-07
Hi;

I have a batch script running on a W2K3 server, (see in code section), this batch file would check if any file exist in K:\PO\archive folder, if it is; it will copy the file to k:\po folder, if not exist, it will display a message.

Howerver; I cannot get "IF NOT EXIST k:\po\archive\*.* GOTO NOFILE" command line working.  It always go to BEGIN section eventhough there is no file in k:\po\archive folder.

Any idea?
@echo off
rem This is a batch program to copy the raw data file from Archive folder back to PO folder
 
:CHK
cls
set folder1=k:\po\archive
set folder2=k:\po
 
IF NOT EXIST k:\po\archive\*.* GOTO NOFILE
 
:BEGIN
dir %folder1%\*.#???????
 
echo.
set /p yn=Confirm to restore this file to K:\PO folder ? y/n 
 
if "%yn%"=="" (echo Not entry) & (GOTO CHK) 
if /I "%yn%"=="n" (GOTO QUIT)
if /I "%yn%"=="y" (GOTO FRESTORE) else (echo Entry not y or n!) & (GOTO CHK)
 
:FRESTORE
ECHO START MOVING...
robocopy %folder1% %folder2% *.*  /mov /maxage:0 /s
 
cls
 
dir k:\po\*.#???????
echo.
echo ************************************************************************
echo ** If you can see the file listed now, your file restore is complete. **
echo ** Run AGAIN.                                          **
echo ************************************************************************
echo.
echo ___________________________________________________________
echo If you do not see the file restored, please try again or 
echo.
echo contact I.T. Dept by e-mail or phone.                    
echo ___________________________________________________________
 
:END
 
echo.
set yn=
set /p yn=Do this again [y/n]?
if "%yn%"=="" (echo Not entry) & (GOTO END) 
if /I "%yn%"=="n" (GOTO QUIT)
if /I "%yn%"=="y" (GOTO CHK) else (echo Entry not y or n!) & (GOTO END)
 
:NOFILE
echo.
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo x No file found in k:\po\archive folder,    x
echo x it could be done already.                 x
echo x No file restore can be done at this time. x 
echo x Asking I.T. Dept for further assistance.  x
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
pause
:QUIT
EXIT

Open in new window

0
Comment
Question by:KANEWONG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Accepted Solution

by:
Francois_IT earned 800 total points
ID: 24787590
replace
 IF NOT EXIST k:\po\archive\*.* GOTO NOFILE

With
dir /b /a k:\po\archive\|findstr .>nul:&&(goto :BEGIN)||(goto :NOFILE)
0
 
LVL 2

Assisted Solution

by:lppperes
lppperes earned 200 total points
ID: 24787619
Hi Kanewong.

Try using these lines:
set file_exist = False
dir %folder1% /b | find /v "Some random string" >nul && (set file_exist=True) || (set file_exist=False)
IF %file_exist% == False GOTO NOFILE

Instead of:
IF NOT EXIST k:\po\archive\*.* GOTO NOFILE
0
 
LVL 1

Author Closing Comment

by:KANEWONG
ID: 31600268
Both solutions work but Francois is simple and what I need.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question