Jump to content

What am I doing wrong?


tazdev
 Share

Recommended Posts

I totally do not understand how to use @comspec. I am trying to get a listing of the My Documents directory and have that placed into c:\temp.txt

In dos I would type

cd\documents and settings\myprofile\my documents

dir *.* /s /b>c:\temp.txt

That would make a temp file with the files listed.

Why doesn't the below work? All I get is an empty file.

$filedir = (@MyDocumentsDir & "\*.* /s /b>c:\temp.txt")

Runwait(@comspec & " /c " & "dir " & $filedir)

Edited by tazdev
Link to comment
Share on other sites

Try this one:

$filedir = ('"' & @MyDocumentsDir & '"' & "\*.* /s /b>c:\temp.txt")
Runwait(@comspec & " /c " & "dir " & $filedir)

Good old DOS Box does not like long path names, especially ones containing spaces... to avoid this problem, you should embrace the path with " and you're done.

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

$filedir = '"' & @MyDocumentsDir & '\*.*" /s /b>c:\temp.txt'
Runwait(@comspec & " /c " & "dir " & $filedir)

Notice the use of single quotes, as to double quotes.

Your Dos equivalent requires quotes also, when spaces are within the address.

:lmao:

Link to comment
Share on other sites

;Example 1
$filedir = @MyDocumentsDir
RunWait(@ComSpec & " /c DIR *.* /S /B>c:\temp.txt", $filedir)

;Example 2
RunWait(@ComSpec & " /c DIR *.* /S /B>c:\temp.txt", @MyDocumentsDir)

;Example 3
RunWait(@ComSpec & ' /c DIR "' & @MyDocumentsDir & '" /S /B>c:\temp.txt')

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