Jump to content

Filemove


Zip
 Share

Recommended Posts

Hello.

I have 3 files in d:\temp\hmmm [2010] wtf- is this

01. Track 1 - hmmm.tmp

02. Track 2 - hmmm.tmp

03. Track 3 - hmmm.tmp

THIS:

$dir= "d:\temp\hmmm [2010] wtf- is this"
$num="3"
FileMove($dir & "\" & "*.tmp", $dir & "\" & $num & "*.tmp", 0)

Results in This:

302. Track 2 - hmmm.tmp

303. Track 3 - hmmm.tmp

3301. Track 1 - hmmm.tmp

:x

even worse:

FileMove($dir & "\" & "*.tmp", $num & "*.tmp", 0)

will delete the files permanently.

can anyone Please help me understand why, thanks!

Edited by Zip
Link to comment
Share on other sites

That's exactly what should happen,

This code

$dir= "d:\temp\hmmm [2010] wtf- is this" 
$num="3"
FileMove($dir & "\" & "*.tmp", $dir & "\" & $num & "*.tmp", 0)

Equals on the destination "d:\temp\hmmm [2010] wtf- is this\3*.tmp"

You are concatenating the $NUM variable with your $DIR variable.

What are you trying to do?

Link to comment
Share on other sites

Hi,

The behavior does seem strange in the first instance.

It appears that FileMove is Moving the first file twice.

eg:

moves 01. Track 1 - hmmm.tmp > 301. Track 1 - hmmm.tmp

moves 301. Track 1 - hmmm.tmp > 3301. Track 1 - hmmm.tmp

Which does seem odd and not expected behavior to me.

In your second instance FileMove($dir & "\" & "*.tmp", $num & "*.tmp", 0)

Doesn't delete the files, it actually moves them to the working directory since you didn't specify a path.

Working Directory would be the script directory unless you specify different.

Also you'll notice that it works correctly as FileMove can't procees the same file twice as it's not there after first move.

My advice would be to either list the files in the directory and then process each file

#include <File.au3>

$dir= "d:\temp\hmmm [2010] wtf- is this"
$aFL2A = _FileListToArray($dir, "*.tmp", 1)
$num="3"
For $i = 1 To $aFL2A[0]
    FileMove($dir & "\" & $aFL2A[$i], $dir & "\" & $num & $aFL2A[$i], 0)
Next

or

If you know the starting letter of the file name then use it with a wild card.

$dir= "d:\temp\hmmm [2010] wtf- is this"
$num="3"
FileMove($dir & "\0*.tmp", $dir & "\" & $num & "*.tmp", 0)

or

Move the files to a new directory then move them back.

$dir= "d:\temp\hmmm [2010] wtf- is this"
$num="3"
FileMove($dir & "\*.tmp", $dir & "\" & $num & "\" & $num & "*.tmp", 8)
FileMove($dir & "\" & $num & "\*.tmp", $dir & "\*.tmp", 0)
DirRemove($dir & "\" & $num)

Not really a solution more a workaround.

Edited by smashly
Link to comment
Share on other sites

Thank you very much smashly .

You are right, Obviously, It appears that FileMove is Moving the first file twice.

That's why I wrote it in the order I wrote it, & said "strange results".

Why does it happen though? a bug?

I am quite a newbie in this so your code is appreciated, thanks !

Link to comment
Share on other sites

Thank you very much smashly .

You are right, Obviously, It appears that FileMove is Moving the first file twice.

That's why I wrote it in the order I wrote it, & said "strange results".

Why does it happen though? a bug?

I am quite a newbie in this so your code is appreciated, thanks !

To be truthful, I don't know if it's a bug.

To me it appears to be a bug.

The reason I say this is it moves the same file twice.

To me there's no logic as if it was meant to do it then why does it only move the first file twice?

But I'm sure others will disagree or have a better theory to justify the behavior.

Since you now know what happens you can only work around it by using better code practices.

Cheers

Link to comment
Share on other sites

You still haven't said what you actually want. We can better help you fix what's wrong if we know what your intent is.

Well I'm a noob, so I want the simplest of things.

Appending a Number to a filename.

cannot figure out if something was wrong with my code:

$dir= "d:\temp\hmmm [2010] wtf- is this"
$num="3"
FileMove($dir & "\" & "*.tmp", $dir & "\" & $num & "*.tmp", 0)

or it is a bug?

Link to comment
Share on other sites

Thanks again smashly, believe it or not, I spent 6 hours on this, insisting on trying different quotes <"> or <'> etc, makes no difference .. :x

Id be grateful If anyone can test it on some Files.

01. Track 1 - hmmm.tmp

02. Track 2 - hmmm.tmp

03. Track 3 - hmmm.tmp

etc.

Link to comment
Share on other sites

Hi,

I've already tried your code and I'm getting the same result.

As I said work around the problem

#include <File.au3>

$dir= "d:\temp\hmmm [2010] wtf- is this"
$aFL2A = _FileListToArray($dir, "*.tmp", 1)
If Not @error Then
    $num="3"
    For $i = 1 To $aFL2A[0]
         FileMove($dir & "\" & $aFL2A[$i], $dir & "\" & $num & $aFL2A[$i], 0)
     Next
Next

Cheers

Edited by smashly
Link to comment
Share on other sites

Hi,

I've already tried your code and I'm getting the same result.

As I said work around the problem

#include <File.au3>

$dir= "d:\temp\hmmm [2010] wtf- is this"
$aFL2A = _FileListToArray($dir, "*.tmp", 1)
If Not @error Then
    $num="3"
    For $i = 1 To $aFL2A[0]
         FileMove($dir & "\" & $aFL2A[$i], $dir & "\" & $num & $aFL2A[$i], 0)
     Next
Next

Cheers

Oh! Thanks for verifying this!

Well tbh as a beginner I am scared to do file operations now on real files after this,

so I think I am gonna do a cmd /c move & be done with it until I figure out what your code means ..

Ill keep your code & study this _FileListToArray, thanks for everything.

btw, Is posting a link to this thread in the Bugs section a good idea, or posting here is enough?

Link to comment
Share on other sites

I just tried the code, added an ENDIF,

#include <File.au3>
$dir= "d:\temp\hmmm [2010] wtf- is this"
$aFL2A = _FileListToArray ($dir, "*.tmp", 1)
If Not @error Then
    $num="3"     
    For $i = 1 To $aFL2A[0]
        FileMove($dir & "\" & $aFL2A[$i], $dir & "\" & $num & $aFL2A[$i], 0)
    Next
EndIf

is that enough for the code to run? got errors.

Link to comment
Share on other sites

hmm, this is getting interesting.

my original idea of resorting back to CMD /C has just turned out to be a joke,

Looks like AutoIT is probably using (or having the same problem as?) Microsoft's CMD with my command. :x

Look at this, typing this into a command prompt:

G:\hmmm [2010] wtf- is this>set d=7& for %i in (*.tmp) do move "%i" "%d%%i"

you will get this:

G:\hmmm [2010] wtf- is this>move "1.Tmp" "71.Tmp"

G:\hmmm [2010] wtf- is this>move "2.Tmp" "72.Tmp"

G:\hmmm [2010] wtf- is this>move "3.Tmp" "73.Tmp"

G:\hmmm [2010] wtf- is this>move "71.Tmp" "771.Tmp"

G:\hmmm [2010] wtf- is this>

Any ideas what's going on ?

Edited by Zip
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...