Sign in to follow this  
Followers 0
Chimaera

Copying File & Folders within its own directory?

9 posts in this topic

Hi been messing with this for a while and im stuck

I have a folder called Test Files

Within that folder is a folder called Music Test

What im trying to do is move the contents of the Test Files Directory whether they be files or folders to a sub directory to be created within the Test Files Directory called Upload

The only way i have managed it so far is by copying them to @TempDir and back into Upload using DirCopy, but the problem is some of the files could be 8GB + so a long copy progress on slow machines is a no no

It seems to resist being moved within itself

Any suggestions please?

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Simply this

$sSetDefault = "E:\Code\Projects\Test Files"

DirCopy($sSetDefault  , $sSetDefault & "\Upload", 1)

But the copy fails because im trying to copy within itself

So how to copy the contents of $sSetDefault then create the folder Upload and move them to $sSetDefault & "Upload"

I tried using RecFileListToArray but it leaves any folders behind and only copies the files

Edited by Chimaera

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You are trying to copy the root directory and place it inside itself. That's never going to work. I imagine you want all files and folders within Test Files placing inside a new folder (Upload - which will be created in the process) within Test Files.

Edited by czardas

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Yes exactly that, thats why im having the problem

TestFiles* To TestFilesUpload

But i cant copy upto 25gig to the temp and back again it would take forever on a slow system

Im not exactly sure while RecFileListToArray leaves the original folders behind... edit prob cos im using FileMove

Do i have to do a DirMove intead?

Local $FindNfo = _RecFileListToArray($sSetDefault, "*", 0, 1)
        ;~  _ArrayDisplay($FindNfo, ".Nfo Files")
            If IsArray($FindNfo) Then
                For $i = 1 To $FindNfo[0]
                    FileMove($sSetDefault & "\" & $FindNfo[$i], $sSetDefault & "\Upload\", 9)
        ;~          Sleep(100)
                Next
                Sleep(100)
            EndIf

Edit 2 I tried DirMove and it deleted all the files and folders within TestFiles

Edited by Chimaera

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

#include <File.au3>

Local $sDir = @ScriptDir & "\Test Files"
Local $sNewFolder = $sDir & "\Upload"

Local $aFiles = _FileListToArray($sDir, "*", 1)
Local $aFolders = _FileListToArray($sDir, "*", 2)

For $i = 1 To $aFiles[0]
    FileMove($sDir & "\" & $aFiles[$i], $sNewFolder & "\" & StringReplace($aFiles[$i], $sDir, ""), 8)
Next

For $i = 1 To $aFolders[0]
    DirMove($sDir & "\" & $aFolders[$i], $sNewFolder & "\" & StringReplace($aFolders[$i], $sDir, ""))
Next

Just replace @ScriptDir with E:CodeProjects

Edited by czardas

Share this post


Link to post
Share on other sites

Thx guys

@Kafu i tried that suggestions but it took 30+ secs to copy 1.8Gig

@czardus that seems to do the ticket and very quickly just a couple of secs

Thanks for the help

1 person likes this

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Thanks Chimaera. I missed checking that the arrays are created with _FilelistToArray. You should add error checking in case there are no files or folders found..

Edited by czardas

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  
Followers 0