Jump to content

[CLOSED] How to open a file that changes slightly in name?


Recommended Posts

A scipt I have creates a text file in the same folder it is run. It date and time stamps the file, i.e., when I launched script earlier I got this text file at the end:

"02- Drives on this Computer- 2008.06.29.Sn, 12h54.txt"

How can I have AI open such a folder when it will always have a different time and date stamp. I tried many variations of this:

ShellExecute(@ScriptDir & "\02- Drives on this Computer-*.txt")
but nothing worked. What am I doing wrong, pls?

Thx much! :)

Edited by Diana (Cda)
Link to comment
Share on other sites

just so you know it is looking for the file "\02- Drives on this Computer-*.txt"

there is no variable in there

sorry if this didnt help

Okay, I'm not sure I understood correctly. I tried various "variables" as you say, and sometimes wildcards work in certain situations with AI, but get the feeling it doesn't here. Alright, trying to move one. Then what does? That's the part I can't figure out yet. The base name will always remain the same, it's the time and date stamp before the .txt extension that will change. How can one get AI to open that file. There shouldn't ever be more than one file there.
Link to comment
Share on other sites

If there aint gonna be more than one file then y not simply use the *.txt instead of tellin it "\02- Drives on this Computer-*.txt" .....not totally sure if this is wat u r lookin for.

Edit :- Btw, when u said "There shouldn't ever be more than one file there." did u mean there wont be more than one file or u meant that u also need assitance on how to delete old files as well ?

Watever the case i guess u can delete old ones n read newer ones with *.txt thingy.

Edited by neo291

I'm not a programmer. Just a Power User.

Link to comment
Share on other sites

See my first post.

Hi, it came through just as I sent out the other. Crossed in cyberspace, as it were ... <g>

I'm afraid I got error messages and I don't know how to fix them. With the code as is, the error is "Unterminated string". So I thought, no problem, and took out what seemed to be an extra quote so that ShellExecute line reads like this:

$files=_FileListToArray(@ScriptDir,"02- Drives on this Computer-*.txt")
But that gives this error:
Func_FilecountLines($sFilePath)

Error:  "Select" statement is missing "EndSelect" or "Case" statement.

? Don't know how to fix this one.

I just dumped those lines in where the ShellExecute line was, after commenting out that ShellExecute line.

Thx. :)

Link to comment
Share on other sites

#include <File.au3>
#include <array.au3>
$files=_FileListToArray(@ScriptDir,"02- Drives on this Computer-*.txt"")
_ArrayDisplay($files)
Hi, guys. Bit depressing here. This doesn't work, as I mentioned. I've tried everything I know, which I know isn't much but I can't figure out what is wrong. I get errors no matter what.

AI is so powerful; is there no way to open up a file that I can't determine ahead of time what it will have in terms of its date/time stamp? This script is part of a larger one. I need to be able to do the above to make this as automated as possible. Having AI open the file, no matter what date-time stamp it has in its name is vital.

As an example of the file names, I ran the script earlier today without the ShellExecute and I got this:

02- Drives on this Computer- 2008.06.29.Sn, 17h27.txt

I ran it just now and got this:

02- Drives on this Computer- 2008.06.29.Sn, 23h51.txt

Because this is a one-time deal each time, I won't have more than 1 text file present. I'll delete any such as this after the tasks are complete; it's just that the large script this smaller one is part of does a lot of things at once. I need to keep the whole process the very least fiddly as possible and that means having AI able to open the text file no matter what date-time stamp is tacked on before the .txt extension; in essence, the format for this text file is this:

02- Drives on this Computer- *.txt

Pls and thanks! :)

Link to comment
Share on other sites

HTML codesnipped

Other than the fact that you may hold great moronic potential, what was your purpose in posting a page of HTML code that has absolutly nothing to do with question at hand?

Has another mental midget joined our ranks? I think so and I'll take this opportunity to say goodbye.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hi, gang. Well, as there's been no further reply, and I don't know how to do this, I'm going to have to go back to not time-date stamping the filename. Bummer, but need the script to work and it's not without being able to open a file with a date and time-stamp.

Thanks much for everyone's attempts. Even though no working solution was found, I appreciate it. muttley

Link to comment
Share on other sites

Thanks. Just a quick comment to close this "thread" ... turns out that I stumbled upon a better solution. I've added the date & time stamp to the text file _itself_ rather than the name. This has turned out to be a better solution. Also tidier; only one text file per script is created so I won't end up with multiple text files. All the data will always be written to the same file, just separating the appended data with some text containing the date and time.

Thanks! muttley

Edited by Diana (Cda)
Link to comment
Share on other sites

  • Moderators

Here's a solution to the original issue:

_RunMaskOpen(@ScriptDir, "\02- Drives on this Computer-*.txt")

Func _RunMaskOpen($s_dir, $s_mask, $s_cmdline = "", $s_workingdir = @WorkingDir)
    $s_dir = StringRegExpReplace($s_dir, "[\\/]+\z", "") & "\"
    $s_mask = StringRegExpReplace($s_mask, "^[\\/]+", "")
    Local $s_file = "", $i_open = 0
    Local $i_PID = Run(@ComSpec & ' /c dir /b /a "' & $s_dir & $s_mask & '" /o-e /od', $s_workingdir, @SW_HIDE, 6)
    While Not @error
        $s_file = StdoutRead($i_PID)
        If FileExists($s_file) Then
            $i_open += 1
            ShellExecute($s_file, $s_cmdline, $s_workingdir)
        Else
            Return SetError(($i_open = 0), $i_open, ($i_open > 0))
        EndIf
    WEnd
EndFunc

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.

Link to comment
Share on other sites

Or what about this:

$FilePattern = "02- Drives on this Computer-*.txt"

; Shows the filenames of matching files in the current directory.
$search = FileFindFirstFile(@SCRIPTDIR & "\" & $FilePattern)

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    MsgBox(4096, "File:", $file)
        ShellExecute($file)
WEnd

; Close the search handle
FileClose($search)
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...