Jump to content

Batch File Help - If Clauses


Recommended Posts

I need to put a line into my batch files like this

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

If path/done.dat exists

EXIT

Else...

do something

rename path/blank.dat to path/done.dat

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

So that this file will only execute if done.dat doesnt exist

Is there a way to do this with a batch file

Thanks for the help

Rob

Link to comment
Share on other sites


IF NOT EXIST "drive\path\blank.dat" (
 IF EXIST "drive\path\done.dat" (
   REN "drive\path\done.dat" "blank.dat"
 )
)

<Edit>

This way it ensures that if the file doesn't already exist it will only rename it if the file you wish to use for the rename procedure exists.

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

Here is the vbs way it checks to see if Winamp Is installed

  Dim Act, Fso, SD

  Set Act = CreateObject("Wscript.Shell")

  Set Fso = CreateObject("Scripting.FileSystemObject")

  SD = Act.ExpandEnvironmentStrings("%SystemDrive%")

  If Not Fso.FileExists( Chr(34) & SD & "\Program Files\Winamp\winamp.exe" & Chr(34))Then

  Act.Popup "Winamp Is Not Installed" & vbCrLf & "Preparing To Exit", 5, "Missing", 0 + 32

  Else

  Act.Popup "Winamp Is Install" ,5, "Confimed", 0 + 32

  End If

Link to comment
Share on other sites

Wow i see ... quick resolutions for a question :thumbup

But what about my problem ? No replies

I simply search for a utility (batch) for my unattended CD

1. Reserve drive Letter C,D,E for Harddisk partitions
dedect CD/RW and DVD-ROM
2. Assign my first DVD (Master Drive) the drive letter F:
   and the CD-RW (Slave Drive) the drive letter  G:

Is there no batch in your pocket for my problem ???

Yzöwl, MHz, gunsmokingman

Thank you in advance

Edited by new_user
Link to comment
Share on other sites

IF NOT EXIST "drive\path\blank.dat" (
 IF EXIST "drive\path\done.dat" (
   REN "drive\path\done.dat" "blank.dat"
 )
)

<Edit>

This way it ensures that if the file doesn't already exist it will only rename it if the file you wish to use for the rename procedure exists.

</Edit>

That's what I used for a "hack job" on one of my batch files while I tried to find a way to prevent it from running after sysprep (silly me, I forgot to include the sysprep,inf, heh). I just copied a file to the root of the drive during the preinstall and deleted it after resealing the machine for the customer. If it existed, the batch file ran and installed the applications. If it did not exist (after resealing), the batch file would simply exit.

Link to comment
Share on other sites

Here a VBS script that will count your drives.

It will not count the drives if this file exists SD & "\TestMe.txt"

If it does not exist then it count your drives

Check For File On SystemDrive

Dim Act, Cnt, Drv, Fso

Set Fso = CreateObject("Scripting.FileSystemObject")

Set Act = CreateObject("Wscript.shell")

Dim SD : SD = Act.ExpandEnvironmentStrings("%systemdrive%")

Cnt = 1-1

Set Drv = Fso.Drives

For Each strD In Drv

If strD.DriveType = 2 Then

If Not Fso.FileExists(SD & "\TestMe.txt") Then

''''Place Action Here for if it not there

Cnt = Cnt +1

Act.Popup "This Is, " & strD & ", Harddrive" & vbCrLf & "Count Number = " & Cnt, 3, "Count Drives", 0 + 32

Else

'''' Place Another Here for if it there

Act.Popup "It Was There", 3, "Confirm", 0 + 32

Exit For

End If

End If

Next

Checks if the TestMe.txt file is on any of the Harddrives or Partition

Dim Act, Cnt, Drv, Fso

Set Fso = CreateObject("Scripting.FileSystemObject")

Set Act = CreateObject("Wscript.shell")

Dim SD : SD = Act.ExpandEnvironmentStrings("%systemdrive%")

Cnt = 1-1

Set Drv = Fso.Drives

For Each strD In Drv

If strD.DriveType = 2 Then

If Not Fso.FileExists(strD & "\TestMe.txt") Then

''''Place Action Here for if it not there

Cnt = Cnt +1

Act.Popup "There Was No TestMe.txt 0n, " & strD & Vbcrlf &  "Count Number = " & Cnt, 3, "Count Drives", 0 + 32

Else

'''' Place Another Here for if it there

Act.Popup "It Was There In This Location" & vbCrLf & strD & "\TestMe.txt", 3, "Confirm", 0 + 32

Exit For

End If

End If

Next

These VBS scripts use the If not Exists statement to check for the file

Tested the script and it works 100% on my computer.

Hope this helps.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...