Jump to content
Sign in to follow this  
program builder

trying to move files to another folder

Recommended Posts

program builder

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

Share this post


Link to post
Share on other sites
Tvern

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

Share this post


Link to post
Share on other sites
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Tvern

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

Share this post


Link to post
Share on other sites
program builder

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

Share this post


Link to post
Share on other sites
Jos

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

Please start using code boxes when posting code.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
program builder

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

Share this post


Link to post
Share on other sites
taietel

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

Share this post


Link to post
Share on other sites
Jos

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
program builder

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

Share this post


Link to post
Share on other sites
Jos

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?

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
program builder

I got it working. I just had to do it in another directory. Maybe someone else could use this code later, if they need it for something. thanks guys.

Share this post


Link to post
Share on other sites
Tvern

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.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.