Sign in to follow this  
Followers 0
onefish

Any Suggestions?

13 posts in this topic

I need to produce a unique identifier for the purposes of moving files with a static path/name to a different path/name. I have written a script that uses a timestamp variable to acomplish this and it works quite well for what it was intended. I now need to generate a script that will move a pdf file from a static path/name to a different path/name and then run the PDF viewer program.exe (which may vary) and open the file that was just moved. The name must be unique to enable the move to take place without overwriting. Two questions if anyone can help:

1. Will the globale timestamp variable I have used previously to name the file change within the same script or is it called one time at the begining of the script and remains the same for all occasions of the variable throughout the script? If there is a better way to accomplish the unique identifier within the script please let me know. I am having trouble passing command line parameters so would like to stay away from them if possible.

2. What is the best way to run the users default PDF viewer?

This will only be my second AutoIT script so please forgive me if the answers to my questions are obvious.

Share this post


Link to post
Share on other sites



1. Will the globale timestamp variable I have used previously to name the file change within the same script or is it called one time at the begining of the script and remains the same for all occasions of the variable throughout the script? 

What "timestamp" variable did you use? Could you please post some code?

If there is a better way to accomplish the unique identifier within the script please let me know.  I am having trouble passing command line parameters so would like to stay away from them if possible.

You could use _TempFile(). Must include file.au3 (see help file for _TempFile()).

2. What is the best way to run the users default PDF viewer?

in a dos box: start test.pdf. In AutoIT: Run() or RunWait() with "start".

NOT tested!

$filename = "c:\test.pdf"
RunWait(@ComSpec & " /c " & "start " & $filename)

This will only be my second AutoIT script so please forgive me if the answers to my questions are obvious.

No problem.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Thank you for the advice. The _TempFile() function should do the trick to name the file. I'll run some tests now to see how the variables act throughout the script. It may not be an issue. The timestamp variable I am using is:

$vari1 = @HOUR & "'" & @MIN & "'" & @SEC & "_"& @MDAY & "'" & @MON & "'" & @YEAR

It seams to work well. Will give your code a try now Kurt.

Cheers

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I can't seam to get the @ComSpec method to work. Error - windows cannot find the file. I imagine I am not using the correct syntax. I have tried the full file path "Documents and Settings\TJOHO\Personal\0968_zones_v11.pdf", the name only and everything in between in the example script above but no luck. What am I doing wrong? I would prefer not to have to specify AcroRd32.exe as some users may prefer another PDF reader (there are much better ones). Script is:

$filename = "Documents and Settings\TJOHO\Personal\0968_zones_v11.pdf"

Run(@COMSPEC & " /c Start "& $filename)

Edited by onefish

Share this post


Link to post
Share on other sites
"Documents and Settings\TJOHO\Personal\0968_zones_v11.pdf" is not a full path. Try using "\Documents and Settings\TJOHO\Personal\0968_zones_v11.pdf" or alternatively you might find @UserProfileDir & "\Personal\0968_zones_v11.pdf" better to do what you want.

Share this post


Link to post
Share on other sites

I think I figured it out. Windows doesn't like spaces in the file name/path. It can't find Documents and Settings. When I put the file in C:\temp no problem. Using the same script. Is there a protocal for declaring spaces in the file name/path?

Share this post


Link to post
Share on other sites

I think I figured it out.  Windows doesn't like spaces in the file name/path.  It can't find Documents and Settings.  When I put the file in C:\temp no problem.  Using the same script.  Is there a protocal for declaring spaces in the file name/path?

<{POST_SNAPBACK}>

i don't think it's an issue with the spaces as it is an issue with the path as LXP pointed out. try throwing a "C:\" infront of the string that's not working and see if that works.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

i don't think it's an issue with the spaces as it is an issue with the path as LXP pointed out.  try throwing a "C:\" infront of the string that's not working and see if that works.

<{POST_SNAPBACK}>

@cameronsdad: Both are right. The path was not correct in the first run and there is a problem with spaces in file names when you start a program in a dos box, because the command interpreter cannot distinguish between the filename and a commandline argument.

start c:\my dir\test.pdf could be just on commandline parameter (the filename c:\my dir\test.pdf) or two, a path (c:\my) and something else (dir\test.pdf).

@onefish: Declare your path variable as follows (single quote followed by double quote!).

$filename = '"C:\Documents and Settings\TJOHO\Personal\0968_zones_v11.pdf"'.

This will create the following command: start "C:\Documents and Settings\TJOHO\Personal\0968_zones_v11.pdf". Now, the command interpreter knows what to do....

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Thanks Kurt,

I had included c:\ in the script and every other drive I have to try and get the script to work prior to posting. But I forgot to include the drive letter in my posted script, oops. Thanks for the advice, it works well. The @ComSpec macro generates a visible command interpretor window. It's only for a flash but I was wondering if there is a way to keep it hidden?

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Works-

$vari = "c:\ICHMStemp\ICHMS.pdf"

Run(@ComSpec & " /c Start " & $vari )

doesn't work-

$vari = "c:\ICHMStemp\ICHMS.pdf"

Run(@ComSpec & " /c Start " & $vari , @sw_HIDE )

It appears @sw_HIDE is being interpreted as part of the file name/path. What am I doing wrong?

Edited by onefish

Share this post


Link to post
Share on other sites

OK got it working by adding another null value

$vari = "c:\ICHMStemp\ICHMS.pdf"

Run(@ComSpec & " /c Start " & $vari , "", @SW_HIDE )

Thank you all for your assistance.

Share this post


Link to post
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
Sign in to follow this  
Followers 0