Jump to content

Autoit doesn't handle "non-traditional" file names?


Recommended Posts

I searched but couldn't find anything so I'll just ask.

Is there a known "bug" that most Autoit file functions don't handle "non-traditional" filenames?

LIke file/folder names that contain characters such as spaces, parentheses "()" and commas?

I need to manipulate literally thousands of files with non-traditional names and none of the file functions seem to work.

Functions like get file attributes and copy folders just puke and die.

An example file name would be like "XX YYYYY-10 ZZ Metals (11111111's).pdf"

And if there is a known bug, how about a quick and easy work around?

Link to comment
Share on other sites

I can't seem to reproduce the problem (at least in my quick testing). Does this script fail for you?

$hFile = FileOpen("XX YYYYY-10 ZZ Metals (11111111's).txt", 2)
FileWrite("XX YYYYY-10 ZZ Metals (11111111's).txt", "test")
FileClose($hFile)
$sAttribs = FileGetAttrib("XX YYYYY-10 ZZ Metals (11111111's).txt")
ConsoleWrite($sAttribs & @CRLF)
FileCopy("XX YYYYY-10 ZZ Metals (11111111's).txt","test.txt")
Edited by spudw2k
Link to comment
Share on other sites

Of course it works.

This doesn't, but I know for a fact the folder does exist. The code tells me it doesn't.

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>


Example()

Func Example()
    Local $sFilePath = "E:\0 Cert Folders\M11111 11111111-3"

    If IsFile($sFilePath) Then
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is a file.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is not a file.")
    EndIf

EndFunc   ;==>Example

Func IsFile($sFilePath)
    If FileExists($sFilePath) Then
      Local $str = FileGetAttrib($sFilePath)
      MsgBox($MB_SYSTEMMODAL, "", "<" & $str & ">")
    Else
      MsgBox($MB_SYSTEMMODAL, "", "not found <" & $sFilePath & ">")
    EndIf
    Return StringInStr(FileGetAttrib($sFilePath), "D") = 0
EndFunc   ;==>IsFile
Link to comment
Share on other sites

Well, it's hard to troubleshoot without a reproducer. Can you come up with an example path that actually fails, so others can try and reproduce? Also, what version of Windows are you running exactly and what kind of filesystem are you working on?

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

its your return, clean that up and all should be fine

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>


Example()

Func Example()
    Local $sFilePath = @ScriptDir & "\0 Cert Folders\M11111 1111111-3"

    If IsFile($sFilePath) Then
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is a file or folder.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is not a file or folder.")
    EndIf

EndFunc   ;==>Example


Func IsFile($sFilePath)
    If FileExists($sFilePath) Then
      Local $str = FileGetAttrib($sFilePath)
      MsgBox($MB_SYSTEMMODAL, "", "<" & $str & ">")
      return 1
    Else
      MsgBox($MB_SYSTEMMODAL, "", "not found <" & $sFilePath & ">")
      return 0
  EndIf
EndFunc   ;==>IsFile

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

 apologies...it worked prior to slapping all that stuff back in and the kids walking through the door, promise.  I'll fix it back

It works in my testing, I will try and break it.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

FileExists() returns true if a file is there OR a folder is there.  You should not be using this to determine if something is a file or folder.  Use DirGetSize() to determine this.

 

afaik DirGetSize() requires a trailing "". could be wrong.

Link to comment
Share on other sites

this works, *with an added msgbox so you can verify that it is the fileexist failing and not your return still being 0 while your example is not going to tell you its a file until you let the return be 1 when you find a match.

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>


Example()

Func Example()
    Local $sFilePath = @ScriptDir & "\0 Cert Folders\M11111 11111111-3"



    If IsFile($sFilePath) Then
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is a file.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is not a file.")
    EndIf

EndFunc   ;==>Example

Func IsFile($sFilePath)
    msgbox(0, '' ,"File Exists = " & fileexists($sFilePath))
    If FileExists($sFilePath) Then
      Local $str = FileGetAttrib($sFilePath)
      MsgBox($MB_SYSTEMMODAL, "", "<" & $str & ">")
      return 1
    Else
      MsgBox($MB_SYSTEMMODAL, "", "not found <" & $sFilePath & ">")
      return 0
    EndIf
EndFunc   ;==>IsFile
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

FileExists() returns true if a file is there OR a folder is there.  You should not be using this to determine if something is a file or folder.  Use DirGetSize() to determine this.

 

afaik DirGetSize() requires a trailing "". could be wrong.

Read the code. I'm not.

Link to comment
Share on other sites

 

this works, *with an added msgbox so you can verify that it is the fileexist failing and not your return still being 0 while your example is not going to tell you its a file until you let the return be 1 when you find a match.

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>


Example()

Func Example()
    Local $sFilePath = @ScriptDir & "\0 Cert Folders\M11111 11111111-3"



    If IsFile($sFilePath) Then
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is a file.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is not a file.")
    EndIf

EndFunc   ;==>Example

Func IsFile($sFilePath)
    msgbox(0, '' ,"File Exists = " & fileexists($sFilePath))
    If FileExists($sFilePath) Then
      Local $str = FileGetAttrib($sFilePath)
      MsgBox($MB_SYSTEMMODAL, "", "<" & $str & ">")
      return 1
    Else
      MsgBox($MB_SYSTEMMODAL, "", "not found <" & $sFilePath & ">")
      return 0
    EndIf
EndFunc   ;==>IsFile

 

You missed the point.

In the code I posted the folder is there. The code tells me it isn't.

Some folders works - others don't.

Link to comment
Share on other sites

Bothose's code works for me. Are you sure the script is located in the root folder above the subfolders "0 Cert FoldersM11111 1111111-3"?

 

EDIT: Post a sample of a file folder path and name that are failing. And stop using bold face, it looks like you're shouting all the time.

Edited by BrewManNH

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 Gude
How 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

wait wait.... i just realized what you are trying to say in boldface, rather than easy reproducers.

 

The problem is the evaluation of the stringinstr return.  not the fileexists.  I would msgbox(0, '' , IsFile($sFilePath)) If that is the area that is telling you it is/is not a file and confirm that the evaluation is correct.

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>


Example()

Func Example()
    Local $sFilePath = @ScriptDir & "\0 Cert Folders\M11111 11111111-3"

;~  $sFilePath = @ScriptDir & "\MOVI0001.avi"

    If NOT stringinstr(IsFile($sFilePath) , "False")  Then
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is a file.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The filepath is not a file.")
    EndIf

EndFunc   ;==>Example

Func IsFile($sFilePath)
    If FileExists($sFilePath) Then
      Local $str = FileGetAttrib($sFilePath)
      MsgBox($MB_SYSTEMMODAL, "", "<" & $str & ">")
    Else
      MsgBox($MB_SYSTEMMODAL, "", "not found <" & $sFilePath & ">")
    EndIf
    Return StringInStr(FileGetAttrib($sFilePath), "D") = 0
EndFunc   ;==>IsFile
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Your code, as posted in post #3, works for me if I create a folder with that name and search for it.

There's nothing wrong with the code, it's working fine as-is, for me.

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 Gude
How 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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...