Jump to content

Trouble with running a cmd command


Recommended Posts

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

Link to post
Share on other sites
  • Moderators

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")

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

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
Link to post
Share on other sites

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?

App: Au3toCmd              UDF: _SingleScript()                             

Link to post
Share on other sites
  • Moderators

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?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

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.

Link to post
Share on other sites

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 !!
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...