Sign in to follow this  
Followers 0
peter1234

How to tell what folder file is in?

9 posts in this topic

I want to write back to the same folder that user uses to input a file, but I do not know what folder will be used. Is there any way to tell what folder a file is in other than by deleting characters from the end of the long file name until there is a backslash? I would think there would be a better way, but I can't find it.

Share this post


Link to post
Share on other sites



I want to write back to the same folder that user uses to input a file, but I do not know what folder will be used. Is there any way to tell what folder a file is in other than by deleting characters from the end of the long file name until there is a backslash? I would think there would be a better way, but I can't find it.

Huh? :P

Ok... is it your Au3.exe your talking about? @ScriptDir should take care of that or @AutoItExe.

If it is a file that your end-user is choosing from your program, why not store it in a variable?

$Var = FileOpenDialog('Open File', @ScriptDir, 'All (*.*)')
MsgBos(0, 'Info', $Var)

Your question is an enigma really...


[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

Can you clarify what you mean by

folder that user uses to input a file

What is this folder that the user is using. Like Smoke N said, is this the folder where the person is running the script?


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I am writing a program to convert an mpeg file to DVD files. The user can choose any mpeg file on his computer to be converted. I have no idea where these files will be stored on his computer. I would like to put the DVD files back in the same folder he has his mpeg file in. I currently put the DVD files on the desktop by using @DesktopDir. I can remove the characters from the end of the file name to find the folder, but I assume there is a user defined function (or some built in fuction) for doing this which would make the code cleaner. However, I have not been able to find such a function. It seems like this would be something used quite often.

Edited by peter1234

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

There's a UDF that should make that easy for you... look at _PathSplit in the help file

Edit... make sure it's the Beta Help File

Edited by SmOke_N

[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

SmOke_N,

Wow, how did you find that? Looks like it will work. Thanks.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Like this:

#include <file.au3>

dim $szDrive, $szDir, $szFName, $szExt
dim $path = "C:\windows\system32\calc.exe"
$arrayPath = _PathSplit($path, $szDrive, $szDir, $szFName, $szExt)
msgbox(0,"", $arrayPath[1] & $arrayPath[2])
Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Works fine. Thanks to both of you.

Share this post


Link to post
Share on other sites

I want to write back to the same folder that user uses to input a file, but I do not know what folder will be used. Is there any way to tell what folder a file is in other than by deleting characters from the end of the long file name until there is a backslash? I would think there would be a better way, but I can't find it.

I always use something like;

$song="C:\My Documents\My Music\song.mp3"

$location=StringMid($song,1,StringInStr($song, "\",0,-1)-1)

MsgBox(0,$song,$location)

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