DssTrainer Posted July 6, 2007 Posted July 6, 2007 (edited) What would be the best way to check if a specified path is a directory or a file? I have a script that allows people to enter a source path and a destination path. If the user enters a source and destination directory like: C:\myDir D:\DestinationDir it will copy ALL files But I need to also be able to handle: C:\myDir\*.exe D:\DestinationDir and C:\myDir\program.* D:\DestinationDir and C:\myDir\*.* D:\DestinationDir What would be the best way to check the string for whether or not it contains a full or partial filename? I was gonna use "FileExists" and based on the error i would decide, but FileExists also supports DirectoryExists functionality (probably a bad idea). So I can't think of any other method. Edited July 6, 2007 by DssTrainer
Toady Posted July 6, 2007 Posted July 6, 2007 FileGetAttrib() www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding
DssTrainer Posted July 6, 2007 Author Posted July 6, 2007 Hmm Doesn't seem to work if I use UNC paths: \\netname\c$\test\xml\myfile.xml just returns a null.
MrCreatoR Posted July 6, 2007 Posted July 6, 2007 And what will return this:FileExists("\\netname\c$\test\xml\nul")?The \\ is defined as root dir (same as StringLeft(@ScriptDir, 2) & "\netname\c$\test\xml\nul") i think, so this file i supose, is not exists . Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
Moderators SmOke_N Posted July 6, 2007 Moderators Posted July 6, 2007 (edited) And what will return this:FileExists("\\netname\c$\test\xml\nul")?The \\ is defined as root dir (same as StringLeft(@ScriptDir, 2) & "\netname\c$\test\xml\nul") i think, so this file i supose, is not exists .Your example is incorrect. Edited July 6, 2007 by SmOke_N 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.
DssTrainer Posted July 6, 2007 Author Posted July 6, 2007 And what will return this:FileExists("\\netname\c$\test\xml\nul")?The \\ is defined as root dir (same as StringLeft(@ScriptDir, 2) & "\netname\c$\test\xml\nul") i think, so this file i supose, is not exists .But \\ is the standard (for windows anyway) to signify a network name.
DW1 Posted July 6, 2007 Posted July 6, 2007 have you tried running that as a different user? AutoIt3 Online Help
DssTrainer Posted July 6, 2007 Author Posted July 6, 2007 (edited) have you tried running that as a different user?Well I can reach that path through Windows directly, and my "FileFindFirstFile($path/*.*)" works on the UNC path. DirGetSize also doesn't work on UNC paths.Most Attribute functions don't work on network paths. I think it might be for other programs, not just AutoIt. Edited July 6, 2007 by DssTrainer
PsaltyDS Posted July 6, 2007 Posted July 6, 2007 Well I can reach that path through Windows directly, and my "FileFindFirstFile($path/*.*)" works on the UNC path. DirGetSize also doesn't work on UNC paths. Most Attribute functions don't work on network paths. I think it might be for other programs, not just AutoIt. You have some other issue. This works fine for me on a networked UNC path: $path = "\\my_server\my_share\my_directory" $file = $path & "\my_file.txt" If FileExists($path & "\") Then MsgBox(64, "Attribs: Dir", FileGetAttrib($path & "\")) MsgBox(64, "Size: Dir", DirGetSize($path & "\")) MsgBox(64, "Attribs: File", FileGetAttrib($file)) Else MsgBox(16, "Error", "Didn't see UNC path") EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
DssTrainer Posted July 6, 2007 Author Posted July 6, 2007 You have some other issue. This works fine for me on a networked UNC path: $path = "\\my_server\my_share\my_directory" $file = $path & "\my_file.txt" If FileExists($path & "\") Then MsgBox(64, "Attribs: Dir", FileGetAttrib($path & "\")) MsgBox(64, "Size: Dir", DirGetSize($path & "\")) MsgBox(64, "Attribs: File", FileGetAttrib($file)) Else MsgBox(16, "Error", "Didn't see UNC path") EndIf Hmm. i will have to see whats going wrong here. Thanks for trying that.
ur Posted July 10, 2015 Posted July 10, 2015 (edited) How can we check whether a value stored in a string is file or folder? Both in UNC and Local paths. Edited July 10, 2015 by ur
Developers Jos Posted July 10, 2015 Developers Posted July 10, 2015 (edited) I am not sure that this question justifies resurrecting and 8 years old thread but check for a "D" in the result of FileGetAttrib(), which was already given as answer earlier in this thread!It works both for UNC and LocalPaths for me.Jos Edited July 10, 2015 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now