Jump to content

finding folders and copying specific data


Recommended Posts

Hello all,

I have a question that is starting to make my head spin, Hopefully you have a easier solution.

I am writing a script to map a network drive to where I store the Microsoft critical patches. What I want it to be able to do is automatically figure out which items the system should have and copy them to a folder on the desktop.

right now I am mapping P: directly to the folder that contains folders for each KB#### I then do a RunWait(@comspec & " /c Dir P:\ /b /a /s /AD > " & $TMP & "dir.txt") to get a text file that looks like this

P:\Archived Files

P:\KB841533

P:\KB873376

P:\KB886836

P:\KB824151

P:\KB841533\2K;SP3;SP4

P:\KB841533\XP;SP0;SP1

P:\KB873376\XP;SP0;SP1

P:\KB824151\2K;SP3;SP4

P:\KB824151\XP;SP0;SP1

I then copy the important data into an INI file using this code

$file = FileOpen(@TempDir & "\dir.txt", 0)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$round = 0
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $Split = stringsplit($line, "\")
    if $split[2] <> "Archived Files" Then
    $round = $round +1
    if $split[0] = 2 Then
    IniWrite(@TempDir & "\dir.ini", "Dir" & $round, "Folder", $split[2])
    EndIf
    if $split[0] = 3 Then
    IniWrite(@TempDir & "\dir.ini", "Dir" & $round, "Folder", $split[2])
    iniwrite(@TempDir & "\dir.ini", "Dir" & $round, "SubFolder", $split[3])
    EndIf
    if $split[0] = 4 Then
    IniWrite(@TempDir & "\dir.ini", "Dir" & $round, "Folder", $split[2])
    iniwrite(@TempDir & "\dir.ini", "Dir" & $round, "SubFolder", $split[3])
    iniwrite(@TempDir & "\dir.ini", "Dir" & $round, "SubFolder2", $split[4])
    EndIf
   EndIf
Wend
FileClose($file)

The output looks like this

[Dir1]

Folder=KB841533

[Dir2]

Folder=KB873376

[Dir3]

Folder=KB886836

[Dir4]

Folder=KB824151

[Dir5]

Folder=KB841533

SubFolder=2K;SP3;SP4

[Dir6]

Folder=KB841533

SubFolder=XP;SP0;SP1

[Dir7]

Folder=KB873376

SubFolder=XP;SP0;SP1

[Dir8]

Folder=KB824151

SubFolder=2K;SP3;SP4

[Dir9]

Folder=KB824151

SubFolder=XP;SP0;SP1

I will then be reading the current systems OS and SP using the AutoIT Macro's then I have to figure out how to determine which SubFolder has the proper files

What I am stumped on is if there is no subFolder than I want to copy the entire contents of the Folder and if there are SubFolders I need to match the OS and SP#, how can I do a Match from a INIREAD :)

Link to post
Share on other sites

[..]

What I am stumped on is if there is no subFolder than I want to copy the entire contents of the Folder and if there are SubFolders I need to match the OS and SP#,  how can I do a Match from a INIREAD :)

<{POST_SNAPBACK}>

Not sure by what you mean - "how can I do a Match from a INIREAD?" .. Hope this helps :)

;Check Subfolders

    $sSubFolder = INIRead(@TempDir & "\dir.ini", "Dir" & $round, "SubFolder", "none")

    If $sSubFolder = "none" then

        ;copy the entire contents of the Folder

        ;copy the entire contents of the Folder

        ;copy the entire contents of the Folder

    Else

        ;split $sSubFolders at ";" and match the OS and SP#

        ;split $sSubFolders at ";" and match the OS and SP#

        ;split $sSubFolders at ";" and match the OS and SP#

    Endif   

Link to post
Share on other sites

OK, Here is what I have now but this just copies every patch file in all of the directories to the desktop folder.

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

DirCopy("d:\Temp\" & $file, @DesktopCommonDir & "\Software Testing\" & $file, 0)

WEnd

FileClose($search)

Each KB folder may have a sub folder named XP;SP0;SP1 or 2K;SP3;SP4 etc. and I need to copy only the folders that are needed.  I have been stuck because I want to do a DirCopy("d:\Temp\" & $file & "\XP*SP1*", @DesktopCommonDir & "\Software Testing\" & $file & "\", 0) but the * is not recognized by dircopy.  are they any other options?


            
        

        

        
    

    

    
        Link to post
        
            
        
        
        

        
            Share on other sites
            

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

        
    

    

                    
                    
                    
                

                    

                    
                    






    

    

    
        
            


    
        
    

            
        
        
            
                

trids
                

    
        
    
             2
    
        
    

            
            
                Posted 
                
            
        
    
    
        

trids

        
            
                Hmmm .. and what have we here?
            
            

            
                


    
        
    

                
            
            Active Members
            
            
                
                    

    
        
    
             2
    
        
    

                    
                
                936 posts

                
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted  
            
            
                
                
            
        
    

    


    
        
        
            
You can route the output of DIR xp*sp1* to a txt file, which you can read into an array and copy from there:
;Collect an array of matching files/folders
    RunWait(@COMSPEC & ' /c DIR "d:\Temp\' & $file & '\XP*SP1*" /b/s > ' & $TMP & '~matches.txt', "", @SW_HIDE)

   ;read the file into an array 
   ;read the file into an array 
   ;read the file into an array 

   ;walk the array and copy the files listed in it
   ;walk the array and copy the files listed in it
   ;walk the array and copy the files listed in it

HTH

:)

:) .. you may be able to simplify by copying from DOS ..!

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...