Jump to content

trying to move files to another folder


Recommended Posts

I am trying to get it to take the picture out of the windows directory named roger,

and put it into member/friends. (roger.jpg) I already have it saved in the windows directory.

but it isn't letting me movie it. I aint writting the code right.

FileMove("c:/windows/Offline Messenger/Member-Members/nametyped.jpg", "c:/windows/Offline Messenger/member/friends")

is the right code, but I am trying to get it to move the picture of the persons name i type in.

Can some one please help me fix this. I have looked all over the help file,

and have been searching the forums for hours. Thanks.

here is the code I am using.

call("main")

func main()

$text = inputbox("offlinemessenger.com ", "Type in the username of a person, who you would like to add as a friend. Or type in the words view friends to see your friends.")

if @error = 1 Then

Exit

EndIf

if $text = ("view friends") then

shellexecute("c:/windows/Offline Messenger/member/friends")

call("main")

endif

if $text = ("view friend's") then

shellexecute("c:/windows/Offline Messenger/member/friends")

call("main")

else

$firstpartofaddress = "c:/windows/Offline Messenger/Member-Members/"

$jpg = ".jpg"

$lastpartofaddress = ", c:/windows/Offline Messenger/member/friends"

$movejpg = $firstpartofaddress & $text & $jpg & $lastpartofaddress

Filemove($movejpg)

call("main")

endif

endfunc

Link to comment
Share on other sites

You where not that far off. Most of the script would have worked, if you hadn't tried to put the separating comma between the parameters for FileMove() inside the parameter string.

However you're making a few mistakes which I've commented. Also you can post code in [autoít] and [/autoít] tags. (with normal i's)

While 1 ;I'll explain this later


;~  Call("main")    ;Call() is not needed when calling a function like this. It's only for very specific purposes.
    main()      ;This is the normal way to call functions
WEnd
Func main() ;The convention would be to start the function name with a "_", but that's just being pedantic :)
    Local $text = InputBox("offlinemessenger.com ", "Type in the username of a person, who you would like to add as a friend. Or type in the words view friends to see your friends.")
    If @error = 1 Then
        Exit
    EndIf
    ;The two statements can be merged. Also the brackets are not needed.
    If $text = "view friends" Or $text = "view friend's" Then
        ShellExecute(@WindowsDir & "\Offline Messenger\member\friends") ;@windows would be correct, even if windows is not installed on the C drive. This is just to increase compatability on other PC's
;~      Call("main") ;calling a function from inside itsself is bad practice and can cause your script to crash. It's better to Return from the function and then start it again. There are a few ways to do this.
        Return ;As the function call on line 3 is in a loop this will restart it.
    Else
        Local $sFrom = @WindowsDir & "\Offline Messenger\Member-Members\" & $text & ".jpg"
        Local $sTo = @WindowsDir & "\Offline Messenger\member\friends\" & $text & ".jpg" ;you still need to specify the filename. Otherwise it would place a file named "friends" in the folder ../Offline Messenger/member/
        FileMove($sFrom, $sTo) ;You can't actually place the comma seperating the parameters in the sting as it would be seen as part of the string. Again, exceptions are possible in very specific cases.
        Return
;~      Call("main")
    EndIf
EndFunc

Hope that helps.

Edit: Changed paths as taietel suggests below and added a trailing backslash to $sTo.

Edited by Tvern
Link to comment
Share on other sites

  • Developers

The parameters of FileMove cannot be in one Variable but need to be seperately specified.

$firstpartofaddress = "c:/windows/Offline Messenger/Member-Members/"
$lastpartofaddress = "c:/windows/Offline Messenger/member/friends"
Filemove($firstpartofaddress & $text & $jpg, $lastpartofaddress)

.. and don't do this in the func:

call("main")

So something like this: (untested)

While 1
    main()
WEnd
Func main()
    $text = InputBox("offlinemessenger.com ", "Type in the username of a person, who you would like to add as a friend. Or type in the words view friends to see your friends.")
    If @error = 1 Then
        Exit
    EndIf
    If $text = ("view friends") Then
        ShellExecute("c:/windows/Offline Messenger/member/friends")
    ElseIf $text = ("view friend's") Then
        ShellExecute("c:/windows/Offline Messenger/member/friends")
    Else
        $firstpartofaddress = "c:/windows/Offline Messenger/Member-Members/"
        $lastpartofaddress = "c:/windows/Offline Messenger/member/friends"
        FileMove($firstpartofaddress & $text & ".jpg", $lastpartofaddress)
    EndIf
EndFunc   ;==>main
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I didn't took a deep look at your script, but what's strikes me was "c:/windows...". Is not supposed to be "c:\windows..."?

I didn't even realise, but you are correct. I think this is corrected by autoit/windows though, so it shouldn't break the script.

I wanted to show another way to do this, but the above posts hold more important information, so be sure to read.run them first.

Global $sText ;It's good practice to start a variable with a letter that describes what type of data it holds. (When it can hold different types of data "v" is used)
While 1 ;unlike some other languages you don't have to put the main script in main()
    $sText = InputBox("offlinemessenger.com ", "Type in the username of a person, who you would like to add as a friend. Or type in the words view friends to see your friends.")
    Switch $sText
        Case False
            Exit
        Case "view friends", "view friend's"
            ShellExecute(@WindowsDir & "\Offline Messenger\member\friends")
        Case Else
            FileMove(@WindowsDir & "\Offline Messenger\Member-Members\" & $sText & ".jpg", @WindowsDir & "\Offline Messenger\member\friends\" & $sText & ".jpg")
    EndSwitch
WEnd

Switch is awesome when responding to the value of a variable :)

Edit: added trailing backslash to the file destination.

Edited by Tvern
Link to comment
Share on other sites

I am using the code you gave me, but it isn't moving the file,

to the other folder. It is doing everything else that I want it

to do. But I am trying to get it to take the file out of one folder and put

it inside of the other folder. Could someone please help. Here is the code that I used.

while 1
    Local $text = InputBox("offlinemessenger.com ", "Type in the username of a person, who you would like to add as a friend. Or type in the words view friends to see your friends.")
    If @error = 1 Then
        Exit
    EndIf
    ;The two statements can be merged. Also the brackets are not needed.
    If $text = "view friends" Or $text = "view friend's" Then
        ShellExecute(@WindowsDir & "/Offline Messenger/member/friends") ;@windows would be correct, even if windows is not installed on the C drive. This is just to increase compatability on other PC's
    Else
        Local $sFrom = @WindowsDir & "/Offline Messenger/Member-Members/" & $text & ".jpg"
        Local $sTo = @WindowsDir & "/Offline Messenger/member/friends" & $text & ".jpg" ;you still need to specify the filename. Otherwise it would place a file named "friends" in the forlder ../Offline Messenger/member/
        FileMove($sFrom, $sTo) ;You can't actually place the comma seperating the parameters in the sting as it would be seen as part of the string. Again, exceptions are possible in very specific cases.
    EndIf
wend
Edited by Jos
added codebox
Link to comment
Share on other sites

  • Developers

You are missing a backslash in the target path after friends.

Please start using code boxes when posting code.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Here is a simplified version of the above. I've moved some photos from directory b to directory c (both are in the scriptdir):

Global $sText
While 1
    $sText = InputBox("test", "type the name of the photo you want to move from the dir b to dir c:")
    Switch $sText
        Case False
            Exit
        Case Else
            $Ret = FileMove(@ScriptDir & "\b\" & $sText & ".jpg", @ScriptDir & "\c\" & $sText & ".jpg")
   If $Ret=1 Then
    MsgBox(0,"","Moved!")
    Exit
   Else
    MsgBox(0,"","There is no photo with this name! Try again!")
   EndIf
    EndSwitch
WEnd
Link to comment
Share on other sites

  • Developers

i tryed it with the backslash and it still isn't working.

so... start debugging:

- make sure the source and target names are coorect by adding Consolewrite()'s (use Alt+d to autogenerate those)

- make sure you have the access to the directory and files.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Your code said that their was no variab;e givin for dim, local global, struct, or const statement.

You do also try to do some work yourself here ...right?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You're blindly trying to move a file at the moment.

Before doing the move you should check if the source file and destination folder exist with FileExists(). You can also set the third parameter of FileMove() to 8 to create the destination folder if it does not exist yet.

The script won't have right to mess around in the windows dir. You can elevate the rights of the script by adding #requireadmin at the top, but it's probably better to work in another location than the windows dir.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...