Jump to content
Sign in to follow this  
speedi

help filecopy

Recommended Posts

speedi

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

Share this post


Link to post
Share on other sites
monoceres

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

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
martin

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.

Share this post


Link to post
Share on other sites
speedi

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

Share this post


Link to post
Share on other sites
martin

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.

Share this post


Link to post
Share on other sites
speedi

I will try it, but later - have some other obligations now.... Thanks!

Share this post


Link to post
Share on other sites
MikeP

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

Share this post


Link to post
Share on other sites
speedi

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

Share this post


Link to post
Share on other sites
speedi

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

Share this post


Link to post
Share on other sites
MikeP

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

Share this post


Link to post
Share on other sites
speedi

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

Share this post


Link to post
Share on other sites
MikeP

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

Share this post


Link to post
Share on other sites
speedi

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

Share this post


Link to post
Share on other sites
MikeP

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

Share this post


Link to post
Share on other sites
MikeP

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

Share this post


Link to post
Share on other sites
speedi

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

Share this post


Link to post
Share on other sites
speedi

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

Share this post


Link to post
Share on other sites
MikeP

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.

Share this post


Link to post
Share on other sites
MikeP

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

Share this post


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
Sign in to follow this  

×