PDA

View Full Version : If this file exist, crate this1 directory and so on, but how



Mastiff
January 23rd, 2006, 07:04 AM
This is what I use now, but I'm sure this can be more elegantly done, so it covers further out in the directories with concatenating and adding +1 all the time, but I don't know how to do that wihout a perpetual loop of adding...

if win.FileExists("M:\\Midlertidig\\VIDEO_TS.IFO")
then
DVDKatalog = "M:\\Midlertidig1"
else
DVDKatalog = "M:\\Midlertidig"
print(DVDKatalog)
return
end

if win.FileExists("M:\\Midlertidig1\\VIDEO_TS.IFO")
then
DVDKatalog = "M:\\Midlertidig2"
else
DVDKatalog = "M:\\Midlertidig1"
print(DVDKatalog)
return
end

if win.FileExists("M:\\Midlertidig2\\VIDEO_TS.IFO")
then
DVDKatalog = "M:\\Midlertidig3"
print(DVDKatalog)
else
DVDKatalog = "M:\\Midlertidig2"
print(DVDKatalog)
return
end

if win.FileExists("M:\\Midlertidig3\\VIDEO_TS.IFO")
then
DVDKatalog = "M:\\Midlertidig4"
print(DVDKatalog)
else
DVDKatalog = "M:\\Midlertidig3"
print(DVDKatalog)
return
end

if win.FileExists("M:\\Midlertidig4\\VIDEO_TS.IFO")
then
DVDKatalog = "M:\\Midlertidig5"
print(DVDKatalog)
else
DVDKatalog = "M:\\Midlertidig4"
print(DVDKatalog)
return
end


(This is to automate DVDShrink 100 %, and Midlertidig means temporary in Norwegian).

danward79
January 23rd, 2006, 07:24 AM
I did some file functions here
http://www.promixis.com/phpBB2/viewtopic.php?t=12196&start=0&postdays=0&postorder=asc&highlight=file

Mastiff
January 23rd, 2006, 07:27 AM
I had looked at that, without really understanding much... Which one of them can go one number higher than the end number of a directory that ends with a number?

danward79
January 23rd, 2006, 10:10 AM
Oh I missed that bit.

Mastiff
January 23rd, 2006, 11:30 AM
OK.

Rob H
January 23rd, 2006, 11:31 AM
function TryNum(root, num)
local DVDKatalog
if win.PathExists(root..num) then
return false, root..(num + 1)
else
return true, root..num
end
end

function FindFreeDir(root)
i = 1

repeat
local flag, path = TryNum(root, i)
if not flag then
i = i + 1
end
until flag

return path
end

FindFreeDir('M:\\Midlertidig')


This starts at M:\Midlertidig1 rather than M:\Midlertidig but that shouldn't be a problem.

Mastiff
January 23rd, 2006, 11:33 AM
Thank you very much! I'm gonna check that out when I get down to the office tomorrow!

Rob H
January 23rd, 2006, 12:02 PM
I haven't actually tested it, but it should be okay.

Mastiff
January 23rd, 2006, 12:41 PM
I couldn't wait to try it, but unfortunately there's something not right. Probably in my implementation of it. I just wanted to test it first, so I put it in a script action all by itself, but running it drives Girder straight into a loop with 100 % CPU usage. And it doesn't come out of it. :cry:

Rob H
January 23rd, 2006, 12:52 PM
It looks as though it should work, so I wonder if it's a scoping issue :-

Try this one



function TryNum(root, num)
if win.PathExists(root..num) then
return false
else
return true, root..num
end
end

function FindFreeDir(root)
i = 1
local flag, path
repeat
flag, path = TryNum(root, i)
if not flag then
i = i + 1
end
until flag

return path
end

FindFreeDir('M:\\Midlertidig')



That seems to work here.

Mastiff
January 23rd, 2006, 01:15 PM
Thanks! That works. What's a scoping issue? Also I assume that this isn't all I need for the action, but this would be, right:
DVDDirectory = FindFreeDir('M:\\Midlertidig')
That sets as the variable the first enumerated directory that doesn't exist. Thanks again!

Rob H
January 23rd, 2006, 01:22 PM
The only real difference between the two was that in the first one I used


repeat
local flag, path = TryNum()
until flag

but in the second I used


local flag, path
repeat
flag, path = TryNum()
until flag

In the first case I suspect that because of the scope of the flag variable the one referred to in 'until flag' would always be nil.