[VB.net] Als file doesntexist then...issue.

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • Biersteker
  • Registratie: Juni 2009
  • Laatst online: 02-10 18:29
Ben echt even de weg kwijt. Heb een proggie, dat een .txt file inlaad, met using en End Using in de streamreader.

Maar dit werkt niet:
code:
1
2
3
4
5
        If System.IO.File.Exists("C:\1.txt") Then
        Else
            Shell("xxxxx.exe >C:\1.txt", AppWinStyle.Hide)

        End If


Dit staat in de body van het programma, dus als 1.txt niet bestaat, dan maakt je een 1.txt (op de correcte manier, dus niet een leeg 1.txt)

Dan run ik dit. En kom ik op het probleem dat 1.txt niet bestaat :S.
Doe ik hier nou echt iets vreemds? Zie ik iets over het hoofd? Komt het doordat Shell("xxxxx.exe >C:\1.txt", AppWinStyle.Hide) eerst klaar moet zijn, voordat de output naar 1.txt gaat?

(Sorry, volgens mij zit ik zelf in een logische lus :S)

Originally, a hacker was someone who makes furniture with an axe.


Acties:
  • 0 Henk 'm!

  • djexplo
  • Registratie: Oktober 2000
  • Laatst online: 01-10 10:52
code:
1
2
3
4
5
shell(path_Name[,style][,wait][,timeout])
path_name = executable file with the full path of the application which it want to call
Style = a model of application window which it want to call (ex minimize,normal etc).
Wait = a boolean value that prescriptive whether shell function has to wait vb.net finish before working. false is the default value.
TimeOut = a wait time that it needful by shell function to start working if Wait in true v

'if it looks like a duck, walks like a duck and quacks like a duck it's probably a duck'


Acties:
  • 0 Henk 'm!

  • eek
  • Registratie: Februari 2001
  • Laatst online: 06-04-2020

eek

@MagickNET

code:
1
If System.IO.File.Exists("C:\1.txt") Then

Mist hier niet een not?

Skill is when luck becomes a habit.


Acties:
  • 0 Henk 'm!

  • Snake
  • Registratie: Juli 2005
  • Laatst online: 07-03-2024

Snake

Los Angeles, CA, USA

Neen, het wordt in de Else gedaan.

@TS: Shell? Really? Kijk eens naar System.Diagnostics.Process, daarmee kan je de output redirecten naar je file.

MSDN: StandardOutput Property

[ Voor 30% gewijzigd door Snake op 07-12-2011 16:35 ]

Going for adventure, lots of sun and a convertible! | GMT-8


Acties:
  • 0 Henk 'm!

  • pedorus
  • Registratie: Januari 2008
  • Niet online
Op zich zou een Not wel duidelijker zijn. :p Als je wil redirecten, dan heb je cmd nodig. Zie bijv. http://bytes.com/topic/vi...et-complex-command-string

Vitamine D tekorten in Nederland | Dodelijk coronaforum gesloten


Acties:
  • 0 Henk 'm!

  • Ryan_
  • Registratie: Februari 2009
  • Laatst online: 11:20
Waarom gebruik je niet gewoon 'WriteAllText'?

Acties:
  • 0 Henk 'm!

  • Biersteker
  • Registratie: Juni 2009
  • Laatst online: 02-10 18:29
Echt, wat hou ik van de input op tweakers. Ik staar me hier al een paar dagen kapot op, (Jaja, ik weet dat Shell eigenlijk niet meer mag :) ) Gelijk nieuwe insteek om het op te lossen. (Soms vraag je je dan ook echt af, waarom heb ik dat niet kunnen vinden). Iedereen die wil, mag me proggie hebben, als ie af is.
Het probleem is dat ik het eerst werkend had als concept. Het moest werken, maar dan ben je op een gegeven moment echt aan het puin ruimen, oude code eruit. Nieuw idee, proberen, werkt, maar niet voor lang. aarrggh.

code:
1
2
3
4
5
6
Dim command As String

command = "systeminfo > C:\temp\sysinfo.txt"

Shell(command, AppWinStyle.MaximizedFocus)
'Process.Start(command)

is toch praktisch gelijk aan:
code:
1
Shell(systeminfo > C:\temp\sysinfo.txt, AppwinStyle.MaximizedFocus)

Dit is trouwens ook nog een probleem, want die autoclosed niet. Vandaar de lelijke .bat oplossing
Heb het trouwens ook via een .bat geprobeerd, en om een of andere reden werkt dat soms. Als ik meestal wel.

code:
1
2
3
@echo off
xxx.exe -x > C:\1.txt
exit

(Nu komt dus de grap: bij cmd xxx.exe -x>C:\1.txt werkt het wel, bij xxx.exe -x> C:\1.txt, werkt het niet) Outputfile word dan xxx.exe -x >1 C:\1.txt.

@Ryan, zou dat kunnen bij een cmd? Nu laat ik namelijk via de prompt/shell de output naar een textfile schrijven, Hoewel ik dit veel liever naar een variable laat schrijven.

[ Voor 46% gewijzigd door Biersteker op 07-12-2011 17:56 ]

Originally, a hacker was someone who makes furniture with an axe.

Pagina: 1