Sign in to follow this  
Followers 0
Jason_A

Can't get DirMove or DirCopy to work

9 posts in this topic

The story is, we've had an application *cough*Mcafee*cough* that has been dropping a folder onto users' PCs often (not every login, but almost.) The folder/directory is always in @TempDir (C:\Documents and Settings\username\Local Settings\Temp\) and is always named like this: "unz17E.tmp" -- just to be clear, it's a directory, not a file, and the "17E" is different every time. Each one is 7-8 MB so over time they build up and cause problems: I deleted 615 of them off of a PC that had 3MB of free space on the hard drive and would not take an update.

Okay, so I've been working DirCopy and DirMove to make sure I had things built right before I moved to DirRemove. However, I can't get them to work at all. This (after a lot of tweaking) is try #1:

$search = FileFindFirstFile(@TempDir & "\unz*")
If $search = -1 Then
    MsgBox(0, "Error", "No Unz* Directories Found")
    Exit
EndIf
$file = FileFindNextFile($search)
If @error = 0 Then
    $filepath = @TempDir & "\" & $file
    MsgBox(4096, "file", $file)
    MsgBox(4096, "filepath", $filepath)
    DirMove($filepath, "C:\Jason")
    FileClose($search)
Else
    Exit
EndIf

Here, the MsgBox's give me accurate information, but nothing ever shows up in C:\Jason. I'm not sure if the "\" in $filepath makes any difference but it doesn't work either way.

My next attempt was to loop through all possible directory names and delete them if they exist. This finds the directories correctly, but still doesn't copy them anywhere.

for $i = 0 to 3822
    $hex = hex($i,3)
    $file = @TempDir & "\unz" & $hex & ".tmp"
    If fileExists($file) Then
        msgbox(4096,"file",$file)
        DirCopy($file,"C:\Jason\")
    Endif
next
Exit

Anybody see any glaring mistakes?

Share this post


Link to post
Share on other sites



The story is, we've had an application *cough*Mcafee*cough* that has been dropping a folder onto users' PCs often (not every login, but almost.) The folder/directory is always in @TempDir (C:\Documents and Settings\username\Local Settings\Temp\) and is always named like this: "unz17E.tmp" -- just to be clear, it's a directory, not a file, and the "17E" is different every time. Each one is 7-8 MB so over time they build up and cause problems: I deleted 615 of them off of a PC that had 3MB of free space on the hard drive and would not take an update.

Okay, so I've been working DirCopy and DirMove to make sure I had things built right before I moved to DirRemove. However, I can't get them to work at all. This (after a lot of tweaking) is try #1:

$search = FileFindFirstFile(@TempDir & "\unz*")
If $search = -1 Then
    MsgBox(0, "Error", "No Unz* Directories Found")
    Exit
EndIf
$file = FileFindNextFile($search)
If @error = 0 Then
    $filepath = @TempDir & "\" & $file
    MsgBox(4096, "file", $file)
    MsgBox(4096, "filepath", $filepath)
    DirMove($filepath, "C:\Jason")
    FileClose($search)
Else
    Exit
EndIf

Here, the MsgBox's give me accurate information, but nothing ever shows up in C:\Jason. I'm not sure if the "\" in $filepath makes any difference but it doesn't work either way.

My next attempt was to loop through all possible directory names and delete them if they exist. This finds the directories correctly, but still doesn't copy them anywhere.

for $i = 0 to 3822
    $hex = hex($i,3)
    $file = @TempDir & "\unz" & $hex & ".tmp"
    If fileExists($file) Then
        msgbox(4096,"file",$file)
        DirCopy($file,"C:\Jason\")
    Endif
next
Exit

Anybody see any glaring mistakes?

Doesn't look like your trying to move or copy directories, looks like you're trying to move and copy files... How about FileMove() / FileCopy()?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Anybody see any glaring mistakes?

DirMove($filepath, "C:\Jason\" & $file) ; to created the same directory in C:\Jason

-or-

DirMove($filepath, "C:\Jason\",1) ; when you want to override anything in C:\Jason

Edited by JdeB

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

maybe

THIS IS FOR FILES

$search = FileFindFirstFile(@TempDir & "\unz*.*")
If $search = -1 Then
    MsgBox(0, "Error", "No Unz* Directories Found")
    Exit
EndIf
DirCreate("C:\Jason")
While 1
    $file = FileFindNextFile($search)
    If @error then ExitLoop
    If @error = 0 Then
        $filepath = @TempDir & "\" & $file
        MsgBox(4096, $file, $filepath)
        FileMove($filepath, "C:\Jason")
    EndIf
WEnd
FileClose($search)

tested

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Doesn't look like your trying to move or copy directories, looks like you're trying to move and copy files... How about FileMove() / FileCopy()?

Nope, they really are directories...

C:\Documents and Settings\jason\Local Settings\Temp>dir /ad unz*
 Volume in drive C has no label.
 Volume Serial Number is 40E7-BA65

 Directory of C:\Documents and Settings\jason\Local Settings\Temp

02/18/2006  08:27 AM    <DIR>         unz17E.tmp
02/20/2006  11:07 AM    <DIR>         unz307.tmp
02/20/2006  11:07 AM    <DIR>         unz308.tmp
               0 File(s)              0 bytes
               3 Dir(s)  64,307,392,512 bytes free

C:\Documents and Settings\jason\Local Settings\Temp>

Share this post


Link to post
Share on other sites

this is for FOLDERS

*** TESTED ***

$search = FileFindFirstFile(@TempDir & "\unz*")
If $search = -1 Then
    MsgBox(0, "Error", "No Unz* Directories Found")
    Exit
EndIf
DirCreate("C:\Jason")
While 1
    $file = FileFindNextFile($search)
    If @error then ExitLoop
    If @error = 0 Then
        $filepath = @TempDir & "\" & $file
    ;$filepath = FileGetLongName($filepath)
        MsgBox(4096, $file, $filepath)
        DirMove($filepath, "C:\Jason", 1)
    EndIf
WEnd
FileClose($search)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

maybe

tested

8)

That sort-of worked since it moved the contents of the first directory it found over to the new folder, but it left the original directory there and didn't do anything with the others (probably not set to overwrite the files.)

I will try your script using DirMove instead.

Share this post


Link to post
Share on other sites

this is for FOLDERS

*** TESTED ***

8)

Cool, thanks, that worked... now I'll just have to figure out what all the differences are. :o

Share this post


Link to post
Share on other sites

Welcome!!

8)


NEWHeader1.png

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  
Followers 0