ericire Posted April 25, 2019 Share Posted April 25, 2019 (edited) Hi before creating a folder with DirCreate, i want to verify if the input path is a valid directory path and not a file path.As long as the file does not exist yet, it is not possible to use FileGetAttrib to discriminate . How can i do this ? Edited April 25, 2019 by ericire Link to comment Share on other sites More sharing options...
Developers Jos Posted April 25, 2019 Developers Share Posted April 25, 2019 So why can't you use FileGetAttrib() and test for it's success/failure? 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. Link to comment Share on other sites More sharing options...
Nine Posted April 25, 2019 Share Posted April 25, 2019 (edited) FileExists () is good for file and directory Edited April 25, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ericire Posted April 25, 2019 Author Share Posted April 25, 2019 (edited) Jos because using DirCreate with a file path create a directory with a file name like toto.csv, and so there is no failure. Edited April 25, 2019 by ericire Link to comment Share on other sites More sharing options...
ericire Posted April 25, 2019 Author Share Posted April 25, 2019 (edited) Nine, FileExists () is for directories or files that are already exist, here, as i said, i want to verify before creating the directory Edited April 25, 2019 by ericire Link to comment Share on other sites More sharing options...
Nine Posted April 25, 2019 Share Posted April 25, 2019 2 minutes ago, ericire said: FileExists () is for directories or files that are already exist, here i want to verify before creating the directory Wrong read help file : Return Value Success: 1. Failure: 0 if path/file does not exist. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ericire Posted April 25, 2019 Author Share Posted April 25, 2019 yes, so how can i use fileExist before creating a folder since it will tell me systematically that this folder does not exist ? Link to comment Share on other sites More sharing options...
BrewManNH Posted April 25, 2019 Share Posted April 25, 2019 How will you determine that what the user wants to create for a folder name is a file path or a directory name? What is your criteria? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
ericire Posted April 25, 2019 Author Share Posted April 25, 2019 the presence of an extension Link to comment Share on other sites More sharing options...
AdamUL Posted April 25, 2019 Share Posted April 25, 2019 A directory name with a dot in it is a valid path. DirCreate will not create a file, only a directories. See the example below. No file is created. Global $sDir = "Dir1\Dir2\Dir.csv" ;Dir.csv is a directory, not a file. If Not DirCreate($sDir) Then Exit 1 Now if you want to restrict directory names, more so than Windows, that is another thing. Adam Link to comment Share on other sites More sharing options...
ericire Posted April 25, 2019 Author Share Posted April 25, 2019 i can get it with stringRight Link to comment Share on other sites More sharing options...
BrewManNH Posted April 25, 2019 Share Posted April 25, 2019 This "WiFi_Configuration Ver 3.6" is a valid directory name, and a real one on my computer. This isn't a file, and there's no way you're going to be able to differentiate between a file name and a directory name using a criteria of "if it has a dot and something after it, it's a file name" If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
ericire Posted April 25, 2019 Author Share Posted April 25, 2019 (edited) Hi AdamUlthe problem is that dircreate will inevitably create a folder named Dir.csv Edited April 25, 2019 by ericire Link to comment Share on other sites More sharing options...
ericire Posted April 25, 2019 Author Share Posted April 25, 2019 Hi BrewManNHyes, damage that there is no function isfile or isdirectory Link to comment Share on other sites More sharing options...
ericire Posted April 25, 2019 Author Share Posted April 25, 2019 so I only have the solution to use stringRight() and verify if there is a dot good evening Link to comment Share on other sites More sharing options...
AdamUL Posted April 25, 2019 Share Posted April 25, 2019 (edited) An Isfile or isdirectory function would not matter as a dot is a valid character in a directory name. If you are just worried about "extensions," then you can do something like this. This will work with a path with an "extension" or not. Global $sDir = "Dir1\Dir2\Dir.csv" $sDir = StringRegExpReplace($sDir, "\.[^.]*$", "") If Not DirCreate($sDir) Then Exit 1 Adam Edited April 25, 2019 by AdamUL Link to comment Share on other sites More sharing options...
jchd Posted April 25, 2019 Share Posted April 25, 2019 (edited) @ericire Wrong answer! Local $aPath = [@ScriptName, ".", "C:\", "H:\MyFolder.special.version 1.2.3.4"] For $s In $aPath _WhatIsPath($s) Next Func _WhatIsPath($sPath) Local $ret = FileGetAttrib($sPath) ConsoleWrite('"' & $ret & '"' & @CRLF) Select Case $ret = "" MsgBox(0, "Result", $sPath & " doesn't exist yet." & @LF & "It *may be* OK to create that directory.") Case StringInStr($ret, "D") MsgBox(0, "Result", $sPath & " is already a directory with attributes " & $ret & @LF & "No need to create it.") Case Else MsgBox(0, "Result", $sPath & " is an existing file with attributes " & $ret & @LF & "Can't create a directory with this name.") EndSelect EndFunc I wonder if you ever read the answer you got here. Edited April 25, 2019 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
ericire Posted April 25, 2019 Author Share Posted April 25, 2019 thanks jchd but that does not answer the initial question of how to distinguish a file path from a folder path before creating it Link to comment Share on other sites More sharing options...
BrewManNH Posted April 25, 2019 Share Posted April 25, 2019 The simple answer is, you can't If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
ericire Posted April 25, 2019 Author Share Posted April 25, 2019 (edited) yes i can just prohibit the point in the last element of the path or filter it as proposed by AdamULthanks to all 😉 Edited April 25, 2019 by ericire Link to comment Share on other sites More sharing options...
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