Jump to content
Sign in to follow this  
sgeva

nested MOVE files cmd?

Recommended Posts

sgeva

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

thank you

Share this post


Link to post
Share on other sites
Andreik

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.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
sgeva

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

Share this post


Link to post
Share on other sites
dbzfanatic

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.

Share this post


Link to post
Share on other sites
oMBRa

U can do it taking each folder one by one then move the files in your folder

Share this post


Link to post
Share on other sites
Sanku1

FileDelete("C:\New Folder\*.JPG")

Read the HelpFile to know more about it.

Share this post


Link to post
Share on other sites
Andreik

Read oMBra suggest.

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

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites
sgeva

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

Share this post


Link to post
Share on other sites
rasim

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

Share this post


Link to post
Share on other sites
sgeva

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

Share this post


Link to post
Share on other sites
rasim

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

Share this post


Link to post
Share on other sites
sgeva

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

Share this post


Link to post
Share on other sites
picaxe

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

for /r %i in (*) do move %i .

Share this post


Link to post
Share on other sites
sgeva

for /r %i in (*) do move %i .
Sorry but it is to much for me. ;)

Please explain the command or refer me .

thank you

Share this post


Link to post
Share on other sites
picaxe

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

Share this post


Link to post
Share on other sites
sgeva

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

Share this post


Link to post
Share on other sites
picaxe

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.

Share this post


Link to post
Share on other sites
sgeva

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

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  

×