Jump to content

File Access Problems


Recommended Posts

:D

This is an interesting behavior I've encountered. As we all know, Window$ supports long filenames and allows spaces as part of the filename. I have a file buried a few directories deep and am executing it as follows:

$RunDir = @ScriptDir & "\MSBlaster\Fix MSblast\Win2K\"

FileChangeDir($RunDir)

RunWait(@ComSpec & " /c " & 'More information.doc', "", @SW_HIDE)

FileChangeDir(@ScriptDir)

As you can see, there's a space imbedded as part of the filename. When I execute the file, it just doesn't GO! IF, however, I remove the space from the filename and replace it with an underscore character and also rename the troublesome file to the same name, it works like a charm.

$RunDir = @ScriptDir & "\MSBlaster\Fix MSblast\Win2K\"

FileChangeDir($RunDir)

RunWait(@ComSpec & " /c " & 'More_information.doc', "", @SW_HIDE)

FileChangeDir(@ScriptDir)

This isn't a problem for me for my particular application since I can rename any files as I need to. This might be a problem for someone who might not be able to rename files for whatever reason however.

By the way, I had to use the FileChangeDir function to be able to access the desired non-executable type files. I tried building the path into a storage variable and concatenating the @ScriptDir macro to the front end of it (including all appropriate back slashes). I then placed it in the "workingdir" parameter of the RunWait function, but it didn't work. This was my work-around. Clunky, but it works.

Link to comment
Share on other sites

Windows doesn't accept single quotes.

Use this (example):

$RunDir = @ScriptDir & "\MSBlaster\Fix MSblast\Win2K\"
FileChangeDir($RunDir)
RunWait(@ComSpec & ' /c "More information.doc"', "", @SW_HIDE)
FileChangeDir(@ScriptDir)
Link to comment
Share on other sites

Appreciate the help. I cut-N-pasted the code into the script and ran it, but no luck! Still won't run!

You haven't chosen a directory to start the file from.

Here's what I would do:

$RunDir = @ScriptDir & "\MSBlaster\Fix MSblast\Win2K"
Run(@ComSpec & ' /c Start "More information.doc"', $RunDir, @SW_HIDE)

Good luck.

Edited by SlimShady
Link to comment
Share on other sites

:D

Received your reply, remmed out my corresponding lines of script and pasted in yours. Checked to ensure the path info was correct, etc. Gave it a test drive.

Observations:

1. Upon executing the selection. it came up in a command window prompt and stopped.

2. Since the %prompt% environmental variable is set to display the path, I validated that the current directory was correct. It opened the window in the directory that

'More information.doc' file is in.

At this point, I attempted to do some research on the web. After some searching, I ran across what may be a potential 'Fly-in-the-ointment'. I'm beginning to wonder if it may not be a compatibility problem with the Window$ NT-based operating systems (NT, 2000, XP, 2003, etc) command-line syntax and AutoIt. Then again, maybe I'm way out to lunch on this! This is definitely one for you experts.

My search turned up issues in NT-based operating systems about attempting to use the START command with filenames that have spaces in them. It basically unceremoniously dumps you out in a command window. The following is one of several links I looked into concerning this.

http://www.winnetmag.com/Article/ArticleID/14589/14589.html

I did attempt to set up the string in the RUN function several different ways with no success. I did get it to at least acknowledge the presence of the .DOC file when I placed a leading set of double-quotes before the filename.

I'm not sure what I have here, but it is definitely over my head. If anyone has any ideas, I'd sure like to know.

Again, SlimShady, I appreciate your time.

Link to comment
Share on other sites

Any time.

I forgot that my solution doesn't work (I had this problem before).

There is a way that does work.

$RunDir = @ScriptDir & "\MSBlaster\Fix MSblast\Win2K"
$file1 = FileGetShortname($RunDir & "\More information.doc")
Run(@ComSpec & " /c Start " & $file1, "", @SW_HIDE)

I can't test this at the moment, but it should work.

Link to comment
Share on other sites

:D

Thanx SlimShady it worked. It looks like the only way to rid of the problem with spaces in the filename is to get rid of the spaces. One way or another. Anyway, it worked. (It still seems like a work-around though) I also tested it against 2 files in the same directory with the same name except for the last character. It named file~1 and the other file~2 and both worked, so it shouldn't be any problem. If I have any other questions, I know how to get in touch. Oh by the way, does anyone know about when the next stable version of AutoIt may be hitting the streets. I'm wanting to see if I can implement a user-friendly interface at work and no one is going to let me do it with an unstable version.

Link to comment
Share on other sites

I use long file names all the time in scripts, I just double up the quotes with single and double quotes, or if I'm using variables to insert the filepath into a command line, i cococonate (sp?) the quotes in, like this:

$rundir = @scriptdir & "\some where\out there"
$FileToOpen = "myfile.doc"
Run(@ComSpec & ' /c Start ' & '"' $RunDir & "\" & $FileToOpen & '"' ,"" , @SW_HIDE)

no need to change dirs or do any of the other stuff... or you could just do one variable with the path and filename:

$PathAndFile = @scriptdir & "\some where\out there\myfile.doc"
Run(@ComSpec & ' /c Start ' & '"' & $PathAndFile & '"' ,"" , @SW_HIDE)

hope that's helpful...

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

:D

Thanx SlimShady it worked. It looks like the only way to rid of the problem with spaces in the filename is to get rid of the spaces. One way or another. Anyway, it worked. (It still seems like a work-around though) I also tested it against 2 files in the same directory with the same name except for the last  character. It named file~1 and the other file~2 and both worked, so it shouldn't be any problem. If I have any other questions, I know how to get in touch. Oh by the way, does anyone know about when the next stable version of AutoIt may be hitting the streets. I'm wanting to see if I can implement a user-friendly interface at work and no one is going to let me do it with an unstable version.

FileGetShortName ( "file" )

Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm

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...