Jump to content

i need help with a script


Recommended Posts

Alrite well this is a semi-pointless script but i just made it for fun.

$dir = InputBox("Enter Directory Name", "Please enter a directory. If it does not exist it will be created", "C:\")
If @error = 1 Then
   Exit
EndIf
If FileExists($dir) Then
   MsgBox(0, "Directory Existed", "Directory: " &$dir& " was found.")
EndIf
If NOT FileExists($dir) then 
   DirCreate($dir)
   MsgBox(0, "Directory Created", "Directory: " &$dir& " created.")
EndIf
$goto = MsgBox(4, "Go there?", "Would you like to go there now?")
Sleep("200")
If $goto = 6 Then
   Run("Explorer " & $dir)
EndIf
$makefile = MsgBox(4, "Create files", "Would you like to create a file in this directory")
$dirend = StringRight($dir, 1)
If $makefile = 6 Then
   $filename = InputBox("File Name", "Please select a name for the follow (including the extention)")
   $filecontent = InputBox("File Content", "Please include the content to go into the file")
   If $dirend = "\" Then
      FileWrite($dir & $filename, $filecontent)
   EndIf
   If Not $dirend = "\" Then
      FileWrite($dir & "\" & $filename, $filecontent)
   EndIf
EndIf

What i dont understand is, if someone makes the source of the directory without a \ at the end, the script wont create the file. the code i wrote for it seems pretty logical :

If Not $dirend = "\" Then
      FileWrite($dir & "\" & $filename, $filecontent)
   EndIf

but i guess theres something wrong with it. plz help

Also i have another question. Does auto it unzip files?

Edited by the_lord_mephy
My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
Link to comment
Share on other sites

You are correct, this is a VERY worthless script. Are you new to programming?

Well here is the solution to your request:

$dir = InputBox("Enter Directory Name", "Please enter a directory. If it does not exist it will be created", "C:\")
If @error = 1 Then
   Exit
EndIf
If FileExists($dir) Then
   MsgBox(0, "Directory Existed", "Directory: " &$dir& " was found.")
EndIf
If NOT FileExists($dir) then 
   DirCreate($dir)
   MsgBox(0, "Directory Created", "Directory: " &$dir& " created.")
EndIf
$goto = MsgBox(4, "Go there?", "Would you like to go there now?")
Sleep("200")
If $goto = 6 Then
   Run("Explorer " & $dir)
EndIf
$makefile = MsgBox(4, "Create files", "Would you like to create a file in this directory")
$dirend = StringRight($dir, 1)
If $makefile = 6 Then
   $filename = InputBox("File Name", "Please select a name for the follow (including the extention)")
   $filecontent = InputBox("File Content", "Please include the content to go into the file")
   If $dirend = "\" Then
      FileWrite($dir & $filename, $filecontent)
   Else
      FileWrite($dir & "\" & $filename, $filecontent)
   EndIf
EndIf

This works, but I don't understand why you had 2 if statements in the first place. For future reference, the Else command picks up all instances where the If and elseif conditions are not met. This could also be written:

$dir = InputBox("Enter Directory Name", "Please enter a directory. If it does not exist it will be created", "C:\")
If @error = 1 Then
   Exit
EndIf
If FileExists($dir) Then
   MsgBox(0, "Directory Existed", "Directory: " &$dir& " was found.")
EndIf
If NOT FileExists($dir) then 
   DirCreate($dir)
   MsgBox(0, "Directory Created", "Directory: " &$dir& " created.")
EndIf
$goto = MsgBox(4, "Go there?", "Would you like to go there now?")
Sleep("200")
If $goto = 6 Then
   Run("Explorer " & $dir)
EndIf
$makefile = MsgBox(4, "Create files", "Would you like to create a file in this directory")
$dirend = StringRight($dir, 1)
If $makefile = 6 Then
   $filename = InputBox("File Name", "Please select a name for the follow (including the extention)")
   $filecontent = InputBox("File Content", "Please include the content to go into the file")
   If $dirend = "\" Then
      FileWrite($dir & $filename, $filecontent)
   ElseIf NOT( $dirend = "\" ) Then
      FileWrite($dir & "\" & $filename, $filecontent)
   EndIf
EndIf

But the extra code is not needed, and the way you had it written had the potential of writting the file twice, or not at all. You may consider revisiting the basics before writting anymore code. Thanks!

*** Matt @ MPCS

Link to comment
Share on other sites

yes, im new to programming. its realy hard to do this but i am just writing a bunch of scripts that use like everything to get to know what everything does. i have no idea how you guys make big programs but iguess i will learn

My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
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
 Share

  • Recently Browsing   0 members

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