Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am not experience vb.net

form1
Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal RootPath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long

Private Const MAX_PATH = 260
Private Sub Form_Load()
Form2.Visible = False
Dim tempStr As String, Ret As Long
Dim file1, file2 As String

'create a buffer string

tempStr = String(MAX_PATH, 0)

'returns 1 when successfull, 0 when failed

Ret = SearchTreeForFile("c:\PROGRAM FILES\", "Proof.XML", tempStr)

If Ret <> 0 Then

'MsgBox " " + Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1)
Label1.Caption = Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1)


Else

MsgBox "File not found!"

End If

End Sub




me program not rename file PROOF.XML to PROOF.XML.bak

how solution help me

target me program

find name PROOF.XML
if PROOF.XML found rename PROOF.XML.bak
if PROOF.XML.bak found and PROOF.XML not found create files PROOF.XML
if PROOF.XML and PROOF.XML.bak found finish

"search folders and files if the target of rename files meet the target and create new files with the name of the target at the location where the target is found"
help me..please
Posted
Updated 28-Dec-09 7:57am
v3

try now, using this...

Imports System.IO


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim filepath As FileInfo
        filepath = GetFilePath()
            If Not filepath Is Nothing Then
                File.Move(filepath.FullName, filepath.DirectoryName + "/" + filepath.Name + ".bak")

            End If
    End Sub

    Public Function GetFilePath() As FileInfo
        Dim files, directories As Array
        Dim fl As String
        Dim filepath As FileInfo
        Dim finfo As FileInfo
        directories = Directory.GetDirectories("c:\Program Files\")
        For Each fl In directories
            files = Directory.GetFiles(fl, "proof.XML", SearchOption.AllDirectories)
            If files.Length > 0 Then
                finfo = New FileInfo(files(0))
                Return finfo
            End If
            
        Next
        Return finfo

    End Function

    Private Sub createfile()

    End Sub
End Class
 
Share this answer
 
Hi Ario

You can use this.. so that you can get rid of the warning message. :-D

Public Function GetFilePath() As FileInfo
        Dim files, directories As Array
        Dim fl As String
        Dim finfo As FileInfo
        finfo  = Nothing
        directories = Directory.GetDirectories("c:\Program Files\")
        For Each fl In directories
            files = Directory.GetFiles(fl, "poof.XML", SearchOption.AllDirectories)
            If files.Length > 0 Then
                finfo = New FileInfo(files(0))
                Return finfo
            End If

        Next
        Return finfo

    End Function
 
Share this answer
 
Hi
You can include the System.IO namespace to the file where you want to check the file existence.

Use this code to check the file.

if File.exists(' c:\program files\.....\proof.xml') then
File.Move('c:\program files\.....\proof.xml','c:\program files\.....\proof.bak.xml');


I think this can help you
 
Share this answer
 
thanks for you

Can you provide more detail with my program
I have tried but not working

I still help my school

I really hope for your help

"search folders and files if the target of rename files meet the target and create new files with the name of the target at the location where the target is found"

thanks ... :(( :((
 
Share this answer
 
v2
For VB 6, you can use the Name function. Example:

Dim FileName As String
Dim NewFileName As String


FileName = "C:\MyFile.txt"
NewFileName = "C:\Text1.txt"
Name FileName As NewFileName
 
Share this answer
 
yes I understand but the file found

"+ Left $ (tempStr, InStr (1, tempStr, Chr $ (0)) - 1)"

and how do I rename it

automatic search in the program files folder we do not know where the folder is known code

Dim FileName As String
Dim NewFileName As String


FileName = "C:\MyFile.txt" ( C:\MyFile.txt <-----target
NewFileName = "C:\Text1.txt" (C:\Text1.txt <-----target
Name FileName As NewFileName

now I do not know the location where the folders and files Not target

not have the target folder in the files just know there must be two files "PROOF.XML found rename PROOF.XML.bak"

if there is a file PROOF.XML rename and create new files


c:\PROGRAM FILES\not found the folder.....\PROOF.XML

not found the folder.....("+ Left $ (tempStr, InStr (1, tempStr, Chr $ (0)) - 1)" )

who knows his address just code "+ Left $ (tempStr, InStr (1, tempStr, Chr $ (0)) - 1)"
 
Share this answer
 
v5
Hi ariodoni,

I wanted some clarification regarding your question.

Don't you know the location in which your target file is located?

If you don't know the exact location... at least you might be knowing the disk drive in which it is located. Don't you?

If you know that I can help you in finding the file and renaming it...
 
Share this answer
 
examples of these files is c: \ program files \ code projec version 1.0 \ components \ PROOF.XML

because the software version upgrate several times so all the same components and different files folder only software version (code projec version 1.0)

c: \ program files \ (projec code version 1.0) 'projec code version 1.0 or version 1.5 code projec

search target files folder c: \ program files \ projec code version 1.0 \ components \ PROOF.XML

its programs so that I can find files created but can not rename files

program files instalan standard .........
software version change folder .... if the new version out (projec code version 1.0)
components ........ Standard instalation
components and files are not changed, just increased component

it is actually the target files in the folder component PROOF.XML and PROOF.XML.bak

if PROOF.XML rename the files in the folder PROOF.XML.bak found files
if if PROOF.XML and

because not always the same folders I use the search facility
find files created after a new file in the folder where the files found

I have not good English language

I hope you understand my problem

example detail
:sigh:
c:\program files\projec code version 1.0
c:\program files \projec code version 2.0
c:\program files \projec code version 3.0

"projec code version xxx" folders always change if there is a new version

xxx = version folder software

its actual target in the folder "projec code version xxx"

"projec code version xxx" in disregard because of frequent changes :sigh:
:((
 
Share this answer
 
v3
Hi aridhoni,

You can use the below code for finding your target file, Proof.XML in the any disk drive like, C:, D: or E:

Public Function GetFilePath() As FileInfo
        Dim files, directories As Array
        'Dim fl As String
        Dim finfo As FileInfo
        directories = Directory.GetDirectories("E:")
        For Each fl In directories
            files = Directory.GetFiles(fl, "Proof.XML", SearchOption.AllDirectories)
            If files.Length > 0 Then
                finfo = New FileInfo(files(0))
                Return finfo
            End If
        Next
        Return finfo
    End Function


Once you find the file... you can rename the file using the below code..:

Dim filepath As FileInfo
        filepath = GetFilePath()
        If Not filepath Is Nothing Then
            File.Move(filepath.FullName, filepath.DirectoryName + "/" + filepath.Name + ".bak")
        End If


Let me know if this code solves your problem.. if not please tell me the problem that you are facing.
 
Share this answer
 
Thank you an idea
Special thanks Lakshmi Prajwal

I am very happy my problem can be solved starting

I try in vb 2008 code no errors but can not work

Imports System.IO


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GetFilePath()
    End Sub
    Public Function GetFilePath() As FileInfo
        Dim files, directories As Array
        Dim fl As String
        Dim filepath As FileInfo
        Dim finfo As FileInfo
        directories = Directory.GetDirectories("c:\Program Files\")
        For Each fl In directories
            files = Directory.GetFiles(fl, "proof.XML", SearchOption.AllDirectories)
            If files.Length > 0 Then
                finfo = New FileInfo(files(0))
                Return finfo
            End If
            filepath = GetFilePath()
            If Not filepath Is Nothing Then
                File.Move(filepath.FullName, filepath.DirectoryName + "/" + filepath.Name + ".bak")

            End If
        Next
        Return finfo

    End Function


        





    Private Sub createfile()

    End Sub
End Class


I frankly was the school not experience

Thanks..

Ario
 
Share this answer
 
v4
Thanks
Special thanks Lakshmi Prajwal

successful programs work proof.xml to proof.xml.bak :-D

FULL CODE ME
Imports System.IO
Imports System.Xml


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim filepath As FileInfo
dim data1,data2 as string
        filepath = GetFilePath()
=============================================
....????
data1=poof.XML
data2=poofold.XML

If System.IO.File.Exists(poof.XML)then  ????
If System.IO.File.Exists(proofold.xml)then ???
exit sub
elseif proofold.xml then
call createfile

=========================================

        If Not filepath Is Nothing Then
            File.Move(filepath.FullName, filepath.DirectoryName + "/" + "proofold.xml")
        call createfile
        End If

    End Sub

    Public Function GetFilePath() As FileInfo
        Dim files, directories As Array
        Dim fl As String
        Dim filepath As FileInfo
        Dim finfo As FileInfo
        directories = Directory.GetDirectories("c:\Program Files\")
        For Each fl In directories
            files = Directory.GetFiles(fl, "poof.XML", SearchOption.AllDirectories)
            If files.Length > 0 Then
                finfo = New FileInfo(files(0))
                Return finfo
            End If

        Next
        Return finfo

    End Function

    Private Sub createfile()
    File.Create( ???????  location proof.xml)

writer.WriteStartDocument()

    End Sub
End Class



Why error :sigh:
Warning 1 Unused local variable: 'filepath'. C:\Documents and Settings\Admin\Local Settings\Application Data\Temporary Projects\WindowsApplication1\Form1.vb 18 13 WindowsApplication1
Warning 2 Variable 'finfo' is used before it has been assigned a value. A null reference exception could result at runtime. C:\Documents and Settings\Admin\Local Settings\Application Data\Temporary Projects\WindowsApplication1\Form1.vb 29 16
WindowsApplication1


works programs
but the error appears 2 Warning:confused:

if found proof.xml rename files proofold.xml (program aready)
createfiles call found a place where proof.xml (in the folder where proof.xml found)
if proof.xml and proofold.xml already found the file where
:)
 
Share this answer
 
v10
Best Special Lakshmi Prajwal ;)

Thank you all for your help I've managed to program it for your assistance
:-O
a very good solution for the asking http://www.codeproject.com/[^]:thumbsup::thumbsup::thumbsup:

Thanks...:cool:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900