AutoHotkey Community

It is currently May 27th, 2012, 2:26 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: February 9th, 2010, 2:00 pm 
Offline

Joined: February 22nd, 2008, 2:43 pm
Posts: 24
I am trying to make a program where the user must choose a folder.

The folder will be inside Z:\Backup

Like Z:\Backup\computer-3d5 or Z:\Backup\computer-gp8

But i want it to report error if the user has choose'n a folder inside one of those computer folders like: Z:\Backup\computer-3d5\test.txt

Code:

;sjekk at z: er mappet
FileGetSize, OutputVar, Z:\Backup

;sjekke at en mappe med samme serienr er laget fra før...eventuellt slette den gamle

VelgFil:
FileSelectFolder, WhichFolder, Z:\Backup, 0, Velg GAMMELT serienr (Dette serienr vil bli endret til det som denne pc'en har)  ; Ask the user to pick a folder.

if ErrorLevel   ; i.e. it's not blank or zero.
{
    MsgBox, Error: Det har skjedd en feil. Du har ikke valgt mappe.
   return
}

;Hvis brukern har valgt Z:\Backup
if WhichFolder = Z:\Backup
{
    MsgBox, You selected wrong folder.
   Goto, VelgFil
}

;Hvis brukern har valgt Z:\Backup\*\
if WhichFolder = Z:\Backup\*\*
{
    MsgBox, You selected wrong folder.
   Goto, VelgFil
}

MsgBox, You selected folder "%WhichFolder%".

_________________
..:: Patchie ::..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 2:25 pm 
Quote:
But i want it to report error if the user has choose'n a folder inside one of those computer folders like: Z:\Backup\computer-3d5\test.txt
If he/she selects a folder without having an access permission for it? So the user should get restricted to his/her individual folder??


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 2:49 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
Not the most elegant solution - but is this the kind of thing you mean?

Code:
BaseFolder := "Z:\Backup"
;sjekk at z: er mappet
FileGetSize, OutputVar, %BaseFolder%

;sjekke at en mappe med samme serienr er laget fra før...eventuellt slette den gamle

VelgFil:
FileSelectFolder, WhichFolder, %BaseFolder%, 0, Velg GAMMELT serienr (Dette serienr vil bli endret til det som denne pc'en har)  ; Ask the user to pick a folder.

if ErrorLevel   ; i.e. it's not blank or zero.
{
    MsgBox, Error: Det har skjedd en feil. Du har ikke valgt mappe.
   return
}

StringReplace, SubFolder, WhichFolder, %BaseFolder%, ""

Loop, Parse, SubFolder, \
{
   WrongFolder := false
   If A_Index = 1
   {
      WrongFolder := true
      Continue
   }
   Else If A_Index > 2
   {
      WrongFolder := true
      Break
   }
}

If WrongFolder
{
   MsgBox, You selected wrong folder.
   Goto, VelgFil
}

MsgBox, You selected folder "%WhichFolder%".


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 3:14 pm 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
Just replace this:
Code:
;Hvis brukern har valgt Z:\Backup
if WhichFolder = Z:\Backup
{
    MsgBox, You selected wrong folder.
   Goto, VelgFil
}

;Hvis brukern har valgt Z:\Backup\*\
if WhichFolder = Z:\Backup\*\*
{
    MsgBox, You selected wrong folder.
   Goto, VelgFil
}

With:
Code:
IfInstring,Whichfolder,Z:\Backup
{
    MsgBox, You selected wrong folder.
   Goto, VelgFil
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 7:13 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
I may be wrong, but I think the OP wants the user to select a folder of the 1st level deeper than "Z:\Backup", but no deeper than that.

So:

1) The user cannot choose "Z:\Backup" as the folder - they must choose a folder within this)
2) The user may not choose a folder equal to or greater than 2 levels deeper than "Z:\Backup"

"Z:\Backup" - Not allowed
"Z:\Backup\Folder1" - OK
"Z:\Backup\Folder1\Folder2" - Not allowed
"Z:\Backup\Folder3" - OK

This is how I read the request anyway.

@patchie - Is the above what you meant? Please let us know if any of the answers given are what you were requesting.

@affe - surely your code will *always* show an error? If the user chooses "Z:\Backup\computer-3d5" (as per the original post), then this will fail with your example replacement, won't it?

Maybe it's just me misunderstanding what is required :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2010, 8:38 am 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
Hy Oceanmachine,
yes, youre right. Ifinstring does the opposite than I wrote. Im sorry for this mistake.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2010, 10:19 am 
Offline

Joined: February 22nd, 2008, 2:43 pm
Posts: 24
ohh..your great :D

OceanMachine: Thats exactly what i needed.

aaffe & Murx: I wanna thank you too for responding :)

_________________
..:: Patchie ::..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2010, 12:40 pm 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
So you could check if Z:\Backup is in the var for the folder. If so, you could count the \`s. If there are two, ok. If less or more than two, msgbox wrong folder.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2010, 1:17 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
aaffe wrote:
So you could check if Z:\Backup is in the var for the folder. If so, you could count the \`s. If there are two, ok. If less or more than two, msgbox wrong folder.


That's what the code I posted does :lol:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2010, 1:27 pm 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
Sorry, didnt read your post.
OceanMachine wrote:
aaffe wrote:
So you could check if Z:\Backup is in the var for the folder. If so, you could count the \`s. If there are two, ok. If less or more than two, msgbox wrong folder.


That's what the code I posted does :lol:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, Google [Bot], LazyMan, rbrtryn and 26 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group