Sign in to follow this  
Followers 0
sneakysmith12

asking a few simple one word answer questions

19 posts in this topic

Can you have a file that is useable in Notepad but does not have a specific extison on it?

Can you search for one on the computer?

Can you write to one/ read specific lines on one?

Thanks

I'm having horrible luck with the help file, so please do not spam that.


Yeah I'm not the greatest at DarkBasic either, but I'm good enough for a link :D A Thread of a W.I.P. that im making

Share this post


Link to post
Share on other sites



1.Yes, to tell you the truth you can open whatever u want up in notepad ;)

2.Yes you can search the computer for files without an extension

3.Sure why not

Share this post


Link to post
Share on other sites

what do you want it to do? or why do you want it to do this?

Share this post


Link to post
Share on other sites

I'm the quite ambitious little boy who is trying to make a program to disable web sites without the script running.

In doing this I'm editing the file named "HOSTS" which is on all versions of Windows 95 or newer.

I've ran in to two problems the first one was answered eariler and this was the second. So from what I see AutoIt is a very solid scripting language.

I need to know this specific thing because when you first edit HOSTS it appears as the following:

127.0.0.1 localhosts

and then you can add 127.0.0.2 www.example.com to block a website.

that simple


Yeah I'm not the greatest at DarkBasic either, but I'm good enough for a link :D A Thread of a W.I.P. that im making

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

take a look at this for getting filenames, if you want to search the entire computer this is going to take some time but it prolly can easily do it i must say , and then you can do _pathsplit on everything and you can use Ubound to get the total amount of files in the array and then check if the extension is what u want then yeah so on

// I didnt write this code Smoke_N made this wonderful UDF//

#include <array.au3>
$file = @DesktopDir
$array = _FileListToArrayEx($file, "*.*", 0, '',True)
_ArrayDisplay($array, '')

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC], 8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        Local $iPid
        If Not $iRecurse Then
            $iPid = Run(@ComSpec & ' /c ' & 'dir "' & $sPath & '\' & $aSplit[$iCC] & '" /b /o-e /od', '', @SW_HIDE, 6)
        Else
            $iPid = Run(@Comspec & ' /c dir /b /s /a "' & $sPath & '\' & $aSplit[$iCC] & '"', '', @SW_HIDE, 6)
        EndIf
        While 1
            $sRead &= StdoutRead($iPid)
            If @error Then ExitLoop
        WEnd
    Next
    If StringStripWS($sRead, 8) = '' Then Return SetError(4, 4, '')
    Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
    Local $sHold
    For $iCC = 1 To $aFSplit[0]
        If $sExclude And StringLeft(StringTrimLeft($aFSplit[$iCC], StringInStr($aFSplit[$iCC], '\', 0, -1)), _
            StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
        Switch $iFlag
            Case 0
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 1
                If StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 2
                If Not StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc
Edited by thatsgreat2345

Share this post


Link to post
Share on other sites

Hehe

Thats the easy part.

Although because I'm searching for a file that I already know where it is, and it is in the windows dir I can set it up like this:

if @OSTYPE = "Win32_Windows" Then
$search = @windowsdir & "\hosts" 
Else
$search = @systemdir & "\drivers\etc\hosts"
EndIf

if $search = -1 then 
    msgbox(0,"error","No files/directories matched the search pattern")
    Exit 
endif
while 1 
    $file = filefindnextfile($search)
        if @error then ExitLoop
WEnd

Which I find a lot more efficent.


Yeah I'm not the greatest at DarkBasic either, but I'm good enough for a link :D A Thread of a W.I.P. that im making

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hehe

Thats the easy part.

Although because I'm searching for a file that I already know where it is, and it is in the windows dir I can set it up like this:

if @OSTYPE = "Win32_Windows" Then
$search = @windowsdir & "\hosts" 
Else
$search = @systemdir & "\drivers\etc\hosts"
EndIf

if $search = -1 then 
    msgbox(0,"error","No files/directories matched the search pattern")
    Exit 
endif
while 1 
    $file = filefindnextfile($search)
        if @error then ExitLoop
WEnd

Which I find a lot more efficent.

ehhe thats cool you arent really doing anything there in that loop i was just giving you an example that would return everything in subfolders and everything Edited by thatsgreat2345

Share this post


Link to post
Share on other sites

you arent really doing anything there in that loop

Not doing anything!

Thanks, but it is.

file named "HOSTS"

This is checking to make sure that I have the file aviable. If it wont load then the rest of the code is useless, although it wont be if I create the file ;).

If you want to see it try the following code

#include <GUIconstants.au3>

if @OSTYPE = "Win32_Windows" Then
$search = @windowsdir & "\hosts" 
Else
$search = @systemdir & "\drivers\etc\hosts"
EndIf

if $search = -1 then 
    msgbox(0,"error","No files/directories matched the search pattern")
    Exit 
endif
while 1 
    $file = filefindnextfile($search)
        if @error then ExitLoop
WEnd
fileclose($search)
fileopendialog("open...",$file,"*.*")

This will show you where the file is regaurdless of where your Win Dir is even if its a Gibberish title like my spelling.


Yeah I'm not the greatest at DarkBasic either, but I'm good enough for a link :D A Thread of a W.I.P. that im making

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

#include <GUIconstants.au3>
if @OSTYPE = "Win32_Windows" Then
$search = @windowsdir & "\hosts"
Else
$search = @systemdir & "\drivers\etc\"
EndIf
If FileExists($search) Then
    $s = FileFindFirstFile($search & "\*.*")
while 1
    $file = filefindnextfile($s)
       If @error then ExitLoop
    If $file = "Hosts" Then
        MsgBox(0,"File Found","Host File Found")
        ExitLoop
    EndIf
    WEnd
EndIf
Run("Notepad.exe")
WinWait("Untitled -")
ControlSetText("Untitled -","","Edit1",Fileread($search & $file))

Edited by thatsgreat2345

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thanks there... I guess.

I didn't copy and paste nor did I intend it to open the file though.

That woud open a dialog directly where Hosts is located. Which is what I was showing.

I'm way past that step if i made it unclear. I've already got the program working excluding the following:

Unblocking a site

- 90% done if what i have works

Loading all sites currently blocked

- have yet to start

Creating an ICON for the program

- if you know how please help

Finding a Free Installer

- Based on Click & Drag

It would be helpful if anyone knows how to edit a line in the following manner

$Remove = _GuiCtrlListFindString($BlockedSitesList,$ItemToRemove)

_GUICtrlListDeleteItem($BlockedSitesList,$Remove)

FileOpen($File,1)

$FileCount = _FileCountLines($File)

$RemoveLineNumber = ; Where i need to find the line number of $Remove in file

_FileWriteToLine($File,$RemoveLineNumber,"",""

FileClose($File)

Edited by sneakysmith12

Yeah I'm not the greatest at DarkBasic either, but I'm good enough for a link :D A Thread of a W.I.P. that im making

Share this post


Link to post
Share on other sites

is this just an example or magical UDfs that you pulled out of your head ahhah , basically you want to read the file find a string on a certain line and then delete it if it matches something

Share this post


Link to post
Share on other sites

basically you want to read the file find a string on a certain line and then delete it if it matches something

EXACTLY !!!

Well thats what i am currently on. The stuff at the begging was just checking the file.

I need to find the line number of it and delete the entire line, it would work if the _ReplaceStringInFile command supported wildcards.

For adding I have it like the following

$Add = XSkinInputBox("Add URL","Type the URL","www.likethis.com")
            _GUICtrlListAddItem($BlockedSitesList,$Add)
            FileOpen($File,1)
            $FileCount = _FileCountLines($File)
            $Counter = $FileCount - 17
            $IpAdd = "127.0.0." & $Counter
            $FileAdd = $IpAdd & " " & $Add
            FileWriteLine($File,$FileAdd)
            FileClose($File)

And I've pulled all the code directly out of the file I'm using right now, although to explain things I may of added a line or too.. In this case i did not.


Yeah I'm not the greatest at DarkBasic either, but I'm good enough for a link :D A Thread of a W.I.P. that im making

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Well i thought of a quick way to do it by creating a temp file. Then it moves it back to the proper location and such. There are probably other efficient ways as well but i got homework to do.

EDIT: DOH _ReplaceStringInFile

#include <File.au3>
$file = FileOpenDialog("Select File","","Any File (*.*)")
$test = _FileReadReplace($file,"TACOOOOOOO","pecan")
If $test = 1 Then MsgBox(0,"asdf","SUCCESS")
If $test = 0 Then MsgBox(0,"asdf","FAILURE")
Func _FileReadReplace($file,$text,$replace)
    Local $null, $path, $temp, $i, $j, $lines
    $lines = _FileCountLines($file)
    $path = _PathSplit($file,$null,$null,$null,$null)
    $temp = @TempDir & "\" & $path[3] & $path[4]
    _FileCreate($temp)
For $i = 1 To $lines
If FileReadLine($file,$i) = $text Then
    For $j = 1 to $i - 1
        FileWrite($temp,FileReadLine($file,$j) & @CRLF)
    Next
    FileWrite($temp,$replace & @CRLF)
    For $i = $i + 1 To $lines
        FileWrite($temp,FileReadLine($file,$i) & @CRLF)
    Next
    FileDelete($file)
    FileMove($temp,$file)
    FileDelete($temp)
    Return 1
ExitLoop
EndIf
Next
Return 0
EndFunc
Edited by thatsgreat2345

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I'll try that out.

Not working for me...

Duplicate function error.

Edited by sneakysmith12

Yeah I'm not the greatest at DarkBasic either, but I'm good enough for a link :D A Thread of a W.I.P. that im making

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

You might want to look into host files - you do not have to change the IP - everything can go to 127.0.0.1 - this might get you started - link

Also if you look at this zip file and look at the batch file contained you will find that a lot of the work has been done for you - also look at the host file. Also you can have them send you the new host file when an new one is created. Mind you if you want popups (adds) - do not use this.

EDIT - Took out quote from previous post

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

everything can go to 127.0.0.1

THATS GREAT... I like counting though lol ;)

For the purpose of this though screw it :lmao:

I actually came up with the following code to ignore that issue while adding and it looked like this:

FileOpen($File,1)
    $FileCount = _FileCountLines($File)
    $Counter = $FileCount - 17
    $IpAdd = "127.0.0." & $Counter
    $FileAdd = $IpAdd & " " & $Add
    FileWriteLine($File,$FileAdd)
    FileClose($File)

So who knows maybe this just looks pretty eheheheheh.

Now this will help when generating a list of already blocked sites :evil: because then could i just split the string and take the part i want?


Yeah I'm not the greatest at DarkBasic either, but I'm good enough for a link :D A Thread of a W.I.P. that im making

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

THATS GREAT... I like counting though lol ;)

For the purpose of this though screw it :lmao:

I am not sure what you are really trying to do - but lets say it is some type of firewall or proxy and you are either trying to block sites or remove blocked sites. Well if you keep adding to the last octect of the IP then you will find you are not blocking anymore - try adding this line to your host file - 127.0.0.255 www.google.com - if you add this line and try to go to the site via browser, it will not show up - "The page cannot be displayed" - Expected right?

Now close the browser and change the last octect to 256 and then open your browser - do you still get "The page cannot be displayed"

You may know all this and plan on 127.0.1.255 and up, but I just thought I would let you know.

EDIT - added proxy

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Did you ever think of FileExists instead of searching?

Share this post


Link to post
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
Sign in to follow this  
Followers 0