Jump to content
Sign in to follow this  
lazyass

Trouble with running a cmd command

Recommended Posts

lazyass

Hi guys!

I'm having some trouble running a simple commandline through AutoIt. The line works when I just put it into a commandprompt or if I'm running it in a batch script, but nothing happens if I run it through an AutoIT script. No errors or anything...

Any help is much appreciated. Thanks in advance.

RunWait(@ComSpec & " /C " & "for /r I:\ %%x in (*.txt) do ren %x *.bak", "", @SW_HIDE)

The batch script that I've got to work looks like this:

@echo off
for /r "I:\" %%x in (*.txt) do ren "%%x" *.bak
exit

Running AutoIt v3.3.6.1

Windows 7 Enterprise Edition SP1 64bit

Share this post


Link to post
Share on other sites
Exit

Try this:

RunWait(@ComSpec & ' /C ' & ' echo for /r "I:" %%x in (*.txt) do ren "%%x" "*.bak" >~.cmd && ~.cmd && del ~.cmd', "", @SW_HIDE)
Edited by forumer100

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, lazyass, welcome to the forum. It appears from your batch file you're trying to rename a bunch of txt files to .bak. Why not do this purely through AutoIT, and skip the middleman? :oops:

Notice I used the Desktop directory, as I have no I: drive mapped.

$dir = @DesktopDir & "Test"
FileMove($dir & "*.txt", $dir & "*.bak")

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
lazyass

Thanks for the effort, forumer100 but it still won't work.

Any other ideas?

@JLogan3o13: I would like to do it purely within AutoIT, so I appreciate your advise. It works at the root of I: but I would like to do it recursively. Any ideas how to do that?

Edited by lazyass

Share this post


Link to post
Share on other sites
Exit

Thanks for the effort, forumer100 but it still won't work.

Any other ideas?

I edited my first post.

RunWait(@ComSpec & ' /C ' & ' echo for /r "I:" %%x in (*.txt) do ren "%%x" "*.bak" >~.cmd && ~.cmd && del ~.cmd', "", @SW_HIDE)

Does it work now?


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, Lazyass. Just so I am clear on your intention, do you want to turn every .txt file on your I: drive to a .bak file?


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
lazyass

I edited my first post.

RunWait(@ComSpec & ' /C ' & ' echo for /r "I:" %%x in (*.txt) do ren "%%x" "*.bak" >~.cmd && ~.cmd && del ~.cmd', "", @SW_HIDE)

Does it work now?

Yes, it works now. Thank you very much!

Hi, Lazyass. Just so I am clear on your intention, do you want to turn every .txt file on your I: drive to a .bak file?

Yes, that's the idea. If you have any solution to do so within AutoIt, I would love to hear about it.

Share this post


Link to post
Share on other sites
Chimaera

Hi, lazyass, welcome to the forum. It appears from your batch file you're trying to rename a bunch of txt files to .bak. Why not do this purely through AutoIT, and skip the middleman? :oops:

Notice I used the Desktop directory, as I have no I: drive mapped.

$dir = @DesktopDir & "Test"
FileMove($dir & "*.txt", $dir & "*.bak")

Thats what he gave you earlier !!

Share this post


Link to post
Share on other sites
lazyass

@Chimaera: And as I wrote...:

@JLogan3o13: I would like to do it purely within AutoIT, so I appreciate your advise. It works at the root of I: but I would like to do it recursively. Any ideas how to do that?

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  

×