Jump to content

help filecopy


Recommended Posts

Can I use filecopy to copy from MyDocuments, starting with a specific folder, copying that folder and files and all subsequent folders and files??

for example:

\mydocuments

---\foldera

---\folderb

---\folderc

---\folderd

I want to copy everything in \Mydocuments starting with \folderc copying to \destinationfolder

Edited by speedi
Link to comment
Share on other sites

Can I use filecopy to copy from MyDocuments, starting with a specific folder, copying that folder and files and all subsequent folders and files??

for example:

\mydocuments

\foldera

\folderb

\folderc

\folderd

I want to copy everything in \Mydocuments starting with \folderc copying to \destinationfolder

You could use

DirCopy(@MyDocumentsDir & "\folderc","PathToDest",1);where PathToDest is the full path

If you want to find all the folders in "My Documents" you can use FileFindFirstsFile and FileFindNextFile.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Not sure what you mean, do you want to copy only folderc or folderc, and d?

I want to copy everything after folderc copy folderc, all files in folderc, folderd, all files in folderd and all files in mydocuments...

I am referring to the folders and files as you would see them with windows explorer when list alphabetically by name...

sorry I wasn't clear...

Link to comment
Share on other sites

I want to copy everything after folderc copy folderc, all files in folderc, folderd, all files in folderd and all files in mydocuments...

I am referring to the folders and files as you would see them with windows explorer when list alphabetically by name...

sorry I wasn't clear...

Don't worry you were quite clear. That's what I thought I was telling you.

Here is what I ws saying in more details. NOT TESTED

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile(@MyDocumentsDir & "\*.*") 

; Check if the search was successful
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
    $fa = FileGetAttrib (@MyDocumentsDir & "\" & $file )
    If StringInStr($fa,"D") Then;it's a directory
        DirCopy(@MyDocumentsDir & "\" & $file, $desinationfolder & "\" & $file,1)
    EndIf
    
    MsgBox(4096, "Copied Folder", $file)
WEnd

; Close the search handle
FileClose($search)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi. try this :)

$destDir = FileSelectFolder("Choose destination folder", "", 1)
$startDir = FileSelectFolder("Choose starting folder", "", 1)
$workingDir = StringRegExpReplace($startDir, "(\\.[^\\]*)\z", "",1)
$startcopy = False

FileChangeDir($workingDir)

$search = FileFindFirstFile("*.*")  
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
    If $workingDir&"\"&$file = $startDir Then $startcopy = True
    If $startcopy Then DirCopy($file, $destDir&"\"&$file, 1)        
WEnd

FileClose($search)
MsgBox(0,"","Done!")

You can put that script wherever you want and it works for any directory..not only Mydocuments since I included a directory selector dialog.

starting folder is your "folderc".. that script will move every folder and files, keeping the file structure, from that 'folderc' to the last directory/file of your main folder, to the destination directory

edit : sorry I misread and was moving the directories.. I edited so now it copies them as you asked

Edited by MikeP
Link to comment
Share on other sites

MikeP, Wow, good thing I had a backup.... The move worked, and then I deleted it from the destination without the recycle bin..... Then I noticed the folders were missing from the source.... Near disaster... Then I saw your revised post and note about move instead of copy...

I need to be more careful....

Now all is restored, and I did the revised routine and it works great with one exception. It does not copy the files in mydocs just the folders from my start folder and the files in those folders.... almost there... thanks for your help.....

Link to comment
Share on other sites

Don't worry you were quite clear. That's what I thought I was telling you.

Here is what I ws saying in more details. NOT TESTED

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile(@MyDocumentsDir & "\*.*") 

; Check if the search was successful
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
    $fa = FileGetAttrib (@MyDocumentsDir & "\" & $file )
    If StringInStr($fa,"D") Then;it's a directory
        DirCopy(@MyDocumentsDir & "\" & $file, $desinationfolder & "\" & $file,1)
    EndIf
    
    MsgBox(4096, "Copied Folder", $file)
WEnd

; Close the search handle
FileClose($search)

Martin, Tried above only change was spelling of "destinationfolder" counldn't see that for awhile...

But it copied a file in the middle of mydocs it was a pdf file... I didn't try any further - thanks... the script from mikep works with one exception...

By the way what is the protocol here when 2 members offer solutions??? I don't want to ruffle any feathers...

Edited by speedi
Link to comment
Share on other sites

I want to copy everything in \Mydocuments starting with \folderc copying to \destinationfolder

it works great with one exception. It does not copy the files in mydocs just the folders from my start folder and the files in those folders.... almost there... thanks for your help.....

well.. your first post was only talking (see your example) about directories so I didn't think you wanted to copy the files but that's not a problem... gimme 5 minutes :)

edit : look I used some of Martin's code but modified to add the files missing the root source folder so there's some of his proposition too ^^

All in all it does the trick. Note that I inverted the folder selections since asking first for the destination and then the source wasn't smart and user-friendly .. so now you're asked for the source.. and then the destination :(

$startDir = FileSelectFolder("Choose starting folder", "", 1)
$destDir = FileSelectFolder("Choose destination folder", "", 1)
$workingDir = StringRegExpReplace($startDir, "(\\.[^\\]*)\z", "",1)
$startcopy = False

FileChangeDir($workingDir)

$search = FileFindFirstFile("*.*")  
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
    $fa = FileGetAttrib ($file)
    If StringInStr($fa,"A") Then
        FileCopy($file, $destDir&"\"&$file, 1)
    EndIf

    If $workingDir&"\"&$file = $startDir Then $startcopy = True
    If $startcopy Then DirCopy($file, $destDir&"\"&$file, 1)    
WEnd

FileClose($search)
MsgBox(0,"","Done!")
Edited by MikeP
Link to comment
Share on other sites

well.. your first post was only talking (see your example) about directories so I didn't think you wanted to copy the files but that's not a problem... gimme 5 minutes :)

edit : look I used some of Martin's code but modified to add the files missing the root source folder so there's some of his proposition too ^^

All in all it does the trick. Note that I inverted the folder selections since asking first for the destination and then the source wasn't smart and user-friendly .. so now you're asked for the source.. and then the destination :(

MikeP, It copied the folders and files as before, but copied just 4 of the files in MyDocuments to the destination... nothing common about the names. Thanks again...

These are the 4 files copied:

C:\testdir\Default.rdp

C:\testdir\DESKTOP.INI

C:\testdir\Powerdsk.GID

C:\testdir\toolbarjan2007.pdc

Link to comment
Share on other sites

I have no clue what could be your problem... Maybe it would help, if that's not too confidential, to give the names of the files not copied..because for me, it copies every directory beginning with the starting directory chosen to the last one in your main folder in alphabetical order, and every single file in your main (here, MyDocuments) directory regarding of the name..

In other words, try to explain more precisely your "but copied just 4 of the files"

edit: actually I got an idea.. are you trying to copy My Shared Folders? (as you can see it via the Explorer).. if so, that's a virtual directory and that might be your issue. My script copies correctly "true" directories. I don't know .. just thinking of that, maybe it's something else.

Edited by MikeP
Link to comment
Share on other sites

I have no clue what could be your problem... Maybe it would help, if that's not too confidential, to give the names of the files not copied..because for me, it copies every directory beginning with the starting directory chosen to the last one in your main folder in alphabetical order, and every single file in your main (here, MyDocuments) directory regarding of the name..

In other words, try to explain more precisely your "but copied just 4 of the files"

edit: actually I got an idea.. are you trying to copy My Shared Folders? (as you can see it via the Explorer).. if so, that's a virtual directory and that might be your issue. My script copies correctly "true" directories. I don't know .. just thinking of that, maybe it's something else.

I am learning. I am trying to understand how your script works when I see that it is checking the attribute of each file to be an "A". The 4 files copied have the attribute "A" and that must be why they are the only files copied.... I can't figure out why your script checks the attribute.... What is that intended to do???

I am not copying My Shared Folders...

MyDocuments has 648 files not counting those in the folders within MyDocuments

GOT IT! I made this change and it worked perfectly... Thanks so very much!!!!

If StringInStr($fa,"D") Then

else

FileCopy($file, $destDir&"\"&$file, 1)

EndIf

One more question.. Can I hard code the start and destination folders instead of selecting them?????

Edited by speedi
Link to comment
Share on other sites

you're learning well... just look there and replace your "A" by "N" (or any file attribute except D which means directory and those are handled by the DirCopy within a condition... if you really wanna copy every file even system files and hidden ones then it's like that : :)

$startDir = FileSelectFolder("Choose starting folder", "", 1)
$destDir = FileSelectFolder("Choose destination folder", "", 1)
$workingDir = StringRegExpReplace($startDir, "(\\.[^\\]*)\z", "",1)
$startcopy = False

FileChangeDir($workingDir)

$search = FileFindFirstFile("*.*") 
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
    $fa = FileGetAttrib ($file)
    If StringInStr($fa,"D") Then
         If $workingDir&"\"&$file = $startDir Then $startcopy = True
         If $startcopy Then DirCopy($file, $destDir&"\"&$file, 1)   
    Else
          FileCopy($file, $destDir&"\"&$file, 1)
    EndIf
WEnd

FileClose($search)
MsgBox(0,"","Done!")
Edited by MikeP
Link to comment
Share on other sites

One more question.. Can I hard code the start and destination folders instead of selecting them?????

just put the path in quotes :

$startDir = "C:\Documents and Settings\Your_Username\Mes documents\"

same with $destDir

Link to comment
Share on other sites

I found the copy did everything except for one file. It was an open file "Outlook.pst". I closed OUTLOOK and then the routine copied everything...

Maybe you missed my one more question.....

One more question.. Can I hard code the start and destination folders instead of selecting them?????

Link to comment
Share on other sites

If you don't mind, I have a technical question....

windows explorer can display a folders contents in many sequences - alpha, by size etc.

How are the files and folders actually kept on the hard disk? In alpha order???

If not , how does findnextfile work....

Link to comment
Share on other sites

I don't have Outlook and won't install it since I clearly hate this software. I opened a .doc word and tried the script.. it did the job (Word is opening the file, creating a hidden temporary file and working on it while closing the real file so it works fine). I guess Outlook is locking the file it is working on and how to override this is beyond my knowledge.. unless like you've done, by closing Outlook.

And yes... I did answer to your previous question.

Link to comment
Share on other sites

If you don't mind, I have a technical question....

windows explorer can display a folders contents in many sequences - alpha, by size etc.

How are the files and folders actually kept on the hard disk? In alpha order???

If not , how does findnextfile work....

nope.. Windows politic to store files in your Harddrive is just..awful. You would have to use a software like O&ODefrag and COMPLETE/Name defragmentation type to actually sort your files physically on your hard drive by alphabetical order.. but this would be temporary since any new file would be stored disorganised so you would have to periodically defragment your drive with this method to keep having your files sorted.

I can't tell you how is implemented FileFindNextFile since I'm not an AutoIt developper.. you would have to check and dig the source code here.

Edited by MikeP
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...