 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Machalel Guest
|
Posted: Fri Feb 10, 2006 6:19 am Post subject: Trying to automate moving files, and its not doing anything! |
|
|
Hi,
I want to create a small program that can move some files from one directory to another. I'll try to explain as well as I can what i'm trying to achieve...
Basically I have a directory full of many different data files with different extensions *.001, *.002, *.003 etc relating to how "current" the file is, and I want to be able to move all files except the last 3 with the largest extensions somewhere else.
For example, I might have files
foo.001, foo.002, foo.003, foo.004
baa.001, baa.002, baa.003, baa.004, baa.005, baa.006
In this case I would move foo.001, baa.001, baa.002, baa.003 to a backup directory and leave the others where they are.
There are lots of files in the directory (like 15,000!) so i'm looking at a way to avoid "drag-and-drop"-ing them all manually.
Any help to fix my little program would be appreciated! I've never used this before...
Thanks in advance!
| Code: |
MsgBox, 4, , Do you want to start the backup process?
IfMsgBox, No
return
; Otherwise, the user picked yes.
Loop,*.*,0,0
{
thisFile=A_LoopFileName
thisExt=A_LoopFileExtension
nextExt=A_LoopFileExtension + 1
nextFile=%thisFile% "." %nextExt%
Loop
{
IfExist,%nextFile%
{
nextExt+=1
nextFile=%thisFile% "." %nextExt%
}
IfNotExist,%nextFile%
{
return
}
}
if (nextExt>thisExt+3)
{
moveExt-=4
Loop
{
moveFile=%thisFile% "." %moveExt%
FileMove,moveFile,C:\Backup
if (moveExt=thisExt)
{
return
} else {
moveExt-=1
}
}
}
}
return
|
|
|
| Back to top |
|
 |
Machalel Guest
|
Posted: Fri Feb 10, 2006 6:20 am Post subject: |
|
|
| I should note that this compiles and runs perfectly... but nothing happens! |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1275
|
Posted: Fri Feb 10, 2006 6:39 am Post subject: |
|
|
With the following:
| Code: | ext = 000
ext++
msgbox, %ext% |
Notice how this results in "1" and not 001, so you need to add 0's according to the length of ext:
| Code: | stringlen, length, ext
if length = 1
ext = 00%ext%
if length = 2
ext = 0%ext% |
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
Machalel Guest
|
Posted: Fri Feb 10, 2006 7:00 am Post subject: |
|
|
ahh i see.
I will try that out  |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Fri Feb 10, 2006 10:03 am Post subject: |
|
|
| Serenity wrote: | | Code: | stringlen, length, ext
if length = 1
ext = 00%ext%
if length = 2
ext = 0%ext% |
|
Or:
| Code: | just = 00%ext%
StringRight ext, just, 3
|
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Machalel Guest
|
Posted: Mon Feb 13, 2006 1:01 am Post subject: |
|
|
hmm...
Well I modified it this morning to add in that little bit of code, but it still doesn't work. It doesnt come up with any errors or anything, it just does nothing!
i'll keep working away at it, but can anyone shed some light?
cheers! |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1275
|
Posted: Mon Feb 13, 2006 5:42 am Post subject: |
|
|
The line below indicates an expression, and is missing the colon symbol:
| Quote: | | nextExt := A_LoopFileExtension+1 |
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
[¤GoO¤]
Joined: 22 Feb 2005 Posts: 60 Location: Sweden
|
Posted: Mon Feb 13, 2006 4:39 pm Post subject: Typo? |
|
|
Hello Machalel!
Maybe you should change:
| Code: |
moveFile=%thisFile% "." %moveExt%
|
to:
| Code: |
moveFile=%thisFile%.%moveExt%
|
or
| Code: |
moveFile:=thisFile "." moveExt
|
*Untested* _________________ "Make everything as simple as possible, but not simpler."
- Albert Einstein (1879-1955) |
|
| Back to top |
|
 |
Machalel Guest
|
Posted: Tue Feb 14, 2006 12:23 am Post subject: |
|
|
Hooray! It's working now!
thanks for the tips guys, here's the final code:
| Code: |
MsgBox, 4, , Do you want to start the backup process?
IfMsgBox, No
return
; Otherwise, the user picked yes.
moveDir = c:\tempmove
moveCounter = 0
Loop,*.*,0,0
{
thisFile = %A_LoopFileName%
StringTrimRight,thisFile,thisFile,4
thisExt = %A_LoopFileExt%
nextExt = %thisExt%
nextExt ++
just = 00%nextExt%
StringRight,nextExt,just,3
nextFile = %thisFile%.%nextExt%
Loop
{
IfExist,%nextFile%
{
nextExt ++
just = 00%nextExt%
StringRight,nextExt,just,3
nextFile = %thisFile%.%nextExt%
}
IfNotExist,%nextFile%
{
break
}
}
tempExt = %thisExt%
tempExt += 3
just = 00%tempExt%
StringRight,tempExt,just,3
if (nextExt > tempExt)
{
moveExt = %nextExt%
moveExt -= 4
Loop
{
just = 00%moveExt%
StringRight,moveExt,just,3
moveFile = %thisFile%.%moveExt%
FileMove,%moveFile%,%moveDir%
moveCounter ++
if (moveExt = thisExt)
{
break
} else {
moveExt --
}
}
}
}
MsgBox, %moveCounter% files were transfered to %moveDir%
return
|
|
|
| Back to top |
|
 |
Machalel Guest
|
Posted: Tue Feb 14, 2006 12:30 am Post subject: |
|
|
just a note:
It only works if all the extensions are consequtive, ie:
xxxx.001
xxxx.002
xxxx.003
xxxx.004
it wont work if the files are:
xxxx.001
xxxx.002
xxxx.004
xxxx.005
(none of these files will be moved)
Ideally I'd fix this problem, but it will have to do for now  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|