Jump to content

Recommended Posts

Posted (edited)

The FileMove command is simple

FileMove("C:Test", "D:Test")

But if i want to use it with different dir, for example put it in "SendTo" dir? Like a script .bat. So the first dir change, and the second is always the same. It's possible?

Thanks

Edited by johnmcloud
Posted

I know the fuction reference. I'll do an example:

Take this .bat:

Dir %1 /oe > c:windowstempList.txt

Save it in SendoTo folder ( %APPDATA%MicrosoftWindowsSendTo )

If right click on a folder -- Send To -- Bat, i have a list of that directory.

I want do the same with autoit, with the function FileMove

Right click on a folder -- Send To -- Autoit .exe

result: Move the folder to destination directory ( the destination is always the same )

I hope I was clear,

Thanks for support

Posted (edited)

you can do it with a batch:

move "%1*.*" D:Test

or in Autoit:

$destination = "D:Test"
If($CmdLine[0] > 0) Then
  FileMove ( $CmdLine[1], $destination)
Else
  MsgBox(0x10,"Error!",$CmdLine[0] & " arguments passed!")
EndIf

Note: This only would move the files in the folder, but no sub-folders

Edited by magodiez
Posted

Thanks JohnOne.

johnmcloud,

At the top of your script add something like this >>

If $CmdLine[0] Then
    For $A = 1 To $CmdLine[0]
        If StringInStr(FileGetAttrib($CmdLine[$A]), "D") Then ; Is a Folder/Directory
            DirMove($CmdLine[$A], "<DESTINATIONPATH>")
        Else ; Otherwise it must be a file.
            FileMove($CmdLine[$A], "<DESTINATIONPATH>")
        EndIf       
    Next
EndIf

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

  On 12/12/2011 at 11:03 AM, 'guinness said:

johnmcloud,

At the top of your script add something like this >>

Thanks guinness,

You script work only with single file, not with directory ( don't doing nothing )

And if can explain the first part of the script?

I don't understand this part:

If $CmdLine[0] Then
    For $A = 1 To $CmdLine[0]

I am here also to learn, thanks for support :D

Edited by johnmcloud
Posted

$CmdLine[0] is number of parameters (for more info http://www.autoitscript.com/autoit3/docs/intro/running.htm#CommandLine)

to work with Directories add the flag 1 to overwrite

DirMove($CmdLine[$A], $destination,1)

and you can also add the flag 8 for files, in case the destination folder is not created

FileMove($CmdLine[$A], $destination,8)

$destination = "D:\Test"
If $CmdLine[0] Then
    For $A = 1 To $CmdLine[0]
  If StringInStr(FileGetAttrib($CmdLine[$A]), "D") Then ; Is a Folder/Directory
            DirMove($CmdLine[$A], $destination,1)
        Else ; Otherwise it must be a file.
            FileMove($CmdLine[$A], $destination,8)
        EndIf
    Next
EndIf
Posted (edited)

Seems people have answered already. When I said 'like this' I should have mentioned that please read the additional remarks in the Help file for the functions DirMove & FIleMove.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

  On 12/12/2011 at 1:55 PM, 'magodiez said:

$CmdLine[0] is number of parameters (for more info http://www.autoitscript.com/autoit3/docs/intro/running.htm#CommandLine)

to work with Directories add the flag 1 to overwrite

DirMove($CmdLine[$A], $destination,1)

and you can also add the flag 8 for files, in case the destination folder is not created

FileMove($CmdLine[$A], $destination,8)

$destination = "D:Test"
If $CmdLine[0] Then
    For $A = 1 To $CmdLine[0]
  If StringInStr(FileGetAttrib($CmdLine[$A]), "D") Then ; Is a Folder/Directory
            DirMove($CmdLine[$A], $destination,1)
        Else ; Otherwise it must be a file.
            FileMove($CmdLine[$A], $destination,8)
        EndIf
    Next
EndIf

Thanks man, work, but i need another example for learn better the function.

I have now made this script:

$source = "C:"
$dest = "C:Test.txt"
RunWait(@ComSpec & " " & "/k" & " "& "dir >" & " " &$dest& " " &$source& "&& Echo. && Echo finished")

Working fine, create a file in C: with the directory of C:

Now i want to apply your scipt into this, but not work, What i'm doing wrong?

$dest = "C:Test.txt"
If $CmdLine[0] Then
    For $A = 1 To $CmdLine[0]
  If StringInStr(FileGetAttrib($CmdLine[$A]), "D") Then ; Is a Folder/Directory
  RunWait(@ComSpec & " " & "/k" & " "& "dir >" & " " &$dest& " " &$CmdLine[$A]& "&& Echo. && Echo finished")
        EndIf
    Next
EndIf
Edited by johnmcloud
Posted (edited)

  On 12/12/2011 at 3:10 PM, 'magodiez said:

that code works fine in my computer... Do you get any error???

Now Work, i don't know what was the problem.

I'll post again:

$dest = "C:TestFile.txt"
If $CmdLine[0] Then
    For $A = 1 To $CmdLine[0]
  If StringInStr(FileGetAttrib($CmdLine[$A]), "D") Then ; Is a Folder/Directory
  RunWait(@ComSpec & " " & "/c" & " "& "dir >" & " " & '"'&$dest& '"' & " " & '"' &$CmdLine[$A]& '"' & " " & "&& Echo. && Echo finished", "", @SW_HIDE)
        EndIf
    Next
EndIf

N.B Why i can't post like Autoit code?. I click OK but nothing happens, maybe is a browser problem...

Thanks guys for support, in particularly magodiez and guinness.

Edited by johnmcloud
Posted
  On 12/12/2011 at 3:21 PM, 'johnmcloud said:

Thanks guys for support, in particularly magodiez and guinness.

You're welcome but I only did about 5% of the work.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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