Jump to content

Recommended Posts

Posted

Is there a command which move all the files from a directory and all its subdir to one dir -- but only files!! ?

thank you

You can use DirMove() or DOS command xcopy.

Posted

You can use DirMove() or DOS command xcopy.

But this cmd moves also the name of the subdir .

I want to move ONLY the files.

thank you

Posted

You could use FileCopy() in a loop. It accepts wildcards so you can move all the files and do a bit of recursion and you'll have everything you need.

Posted (edited)

Read oMBra suggest.

Use _FileReadToArray to put all files from one dir in one array and then you can use FileCopy().

Edited by Andreik
Posted (edited)

Read oMBra suggest.

Use _FileReadToArray to put all files from one dir in one array and then you can use FileCopy().

Thank all of you for your help.

I write it in this way:

FileChangeDir("my_dir")

; Shows the dirnames in the current directory.

$search = FileFindFirstFile("my_dir\*.*")

While 1

$dir = FileFindNextFile($search)

If @error Then ExitLoop

; move all the mp3 files in every dir found

FileMove( $dir & "\*.mp3", "target_dir", 9)

WEnd

; Close the search handle

FileClose($search)

Edited by sgeva
Posted

Thank all of you for your help.

I write it in this way:

FileChangeDir("my_dir")

; Shows the dirnames in the current directory.

$search = FileFindFirstFile("my_dir\*.*")

While 1

$dir = FileFindNextFile($search)

If @error Then ExitLoop

; move all the mp3 files in every dir found

FileMove( $dir & "\*.mp3", "target_dir", 9)

WEnd

; Close the search handle

FileClose($search)

But your code don`t processing subdirectories. Example:

_FileMoveEx("d:\Music\Metallica", "c:\Test", "mp3")

Func _FileMoveEx($sSource, $sDest, $sExt)
    Local $iSearch = FileFindFirstFile($sSource & "\*.*")
    If $iSearch = -1 Then Return SetError(1, 0, 0)
    
    Local $sFile, $sFullFile
    
    While 1
        $sFile = FileFindNextFile($iSearch)
        If @error Then ExitLoop
        
        $sFullFile = $sSource & "\" & $sFile
        
        If StringInStr(FileGetAttrib($sFullFile), "D") Then _FileMoveEx($sFullFile, $sDest, $sExt)
        If StringRight($sFullFile, 4) = ".mp3" Then FileMove($sFullFile, $sDest)
    WEnd
    
    FileClose($iSearch)
EndFunc
Posted

But your code don`t processing subdirectories. Example:

_FileMoveEx("d:\Music\Metallica", "c:\Test", "mp3")

Func _FileMoveEx($sSource, $sDest, $sExt)
    Local $iSearch = FileFindFirstFile($sSource & "\*.*")
    If $iSearch = -1 Then Return SetError(1, 0, 0)
    
    Local $sFile, $sFullFile
    
    While 1
        $sFile = FileFindNextFile($iSearch)
        If @error Then ExitLoop
        
        $sFullFile = $sSource & "\" & $sFile
        
        If StringInStr(FileGetAttrib($sFullFile), "D") Then _FileMoveEx($sFullFile, $sDest, $sExt)
        If StringRight($sFullFile, 4) = ".mp3" Then FileMove($sFullFile, $sDest)
    WEnd
    
    FileClose($iSearch)
EndFunc
thank you

I am a beginner but I try my program .

I create test case: I create a dir : my_dir and put under it 2 subdirectories t1 and t2

Then I put 2 files in t1 and 2 files in t2.

The program moved the 4 files from subdirectors t1 t2 to target dir

I am missing something?

thank you

Posted

thank you

I am a beginner but I try my program .

I create test case: I create a dir : my_dir and put under it 2 subdirectories t1 and t2

Then I put 2 files in t1 and 2 files in t2.

The program moved the 4 files from subdirectors t1 t2 to target dir

I am missing something?

thank you

What wrong? You asked:

Is there a command which move all the files from a directory and all its subdir to one dir -- but only files!! ?

Posted

What wrong? You asked:

I do not undersatnd.

I applied my program to my_dir and the program found the subdir t1 and t2 and moved only their files without the name of the dir t1 t2.

Do you know a command which can do it without the need of writing a program?

thank you

Posted (edited)

This windows (tested on winxp) commandline

for /r %i in (*) do move %i .
will move all files from a subdir of the current dir to the current dir

Is there a command which move all the files from a directory and all its subdir to one dir -- but only files!! ?

thank you

or
for /r c:\temp\tmp %i in (*) do move %i \zzz
move all files from c:\temp\tmp and its subdirs to c:\zzz. Move only works where source and destination dirs are on the same drive. Of course you will need to do a copy/delete otherwise. Edited by picaxe
Posted

This windows (tested on winxp) commandline

for /r %i in (*) do move %i .
will move all files from a subdir of the current dir to the current dir or
for /r c:\temp\tmp %i in (*) do move %i \zzz
move all files from c:\temp\tmp and its subdirs to c:\zzz. Move only works where source and destination dirs are on the same drive. Of course you will need to do a copy/delete otherwise.
1. I try to compile this command :

for /r D:\test %i in (*) do move %i D:\test1

and get error : ERROR: syntax error

for /

~~~~^

2. what is the meaning of %i and /r?

3. copy has no limits of the same drive for source and destination which move has?

thank you

Posted

It's windows command line, so in AutoIt you need something like

$source = "c:\temp\tmp"
$destination = "c:\zzz"
Run(@ComSpec & ' /c for /r "' & $source & '" %i in (*) do move %i "' & $destination & '"')
%i is not an AutoIt variable, it's used by the "for" command. Type "help for" in a windows cmd window or Google "windows xp for command" for more info.

Posted

It's windows command line, so in AutoIt you need something like

$source = "c:\temp\tmp"
$destination = "c:\zzz"
Run(@ComSpec & ' /c for /r "' & $source & '" %i in (*) do move %i "' & $destination & '"')
%i is not an AutoIt variable, it's used by the "for" command. Type "help for" in a windows cmd window or Google "windows xp for command" for more info.
Thank you very much

I have learned a lot from you. ;)

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
×
×
  • Create New...