Author Topic: Any ideas on SHELL behavior (dir versus attrib)?  (Read 3982 times)

0 Members and 1 Guest are viewing this topic.

Offline LM

  • Newbie
  • Posts: 28
    • View Profile
Any ideas on SHELL behavior (dir versus attrib)?
« on: March 29, 2021, 05:10:44 pm »
I don't understand why this won't work for me.  Any ideas?  I tried it on Windows 8.0 and 10, and I tried both QB64 v1.4 and 1.5.  Here is my problem:

Shell "dir /s >textfile.txt" correctly produces "textfile.txt" like I expect.

Shell "attrib /s >textfile.txt" does not produce the expected "textfile.txt"

If I just run Shell from a QB64 program and manually type "attrib /s >textfile.txt", it does correctly produce the text file.

If I make a .bat file (e.g., "createtextfile.bat") containing "attrib /s >textfile.txt" and then do Shell "createtextfile.bat", then the "textfile.txt" is created.

Any ideas on why attrib won't work from within the QB64 program?  Perhaps there is a more elegant way of getting a listing of all files in the current directory and its sub directories.  I appreciate ideas on that too!

LM
« Last Edit: March 29, 2021, 05:21:49 pm by LM »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Any ideas on SHELL behavior (dir versus attrib)?
« Reply #1 on: March 29, 2021, 05:23:31 pm »
I don't understand why this won't work for me.  Any ideas?  I tried it on Windows 8.0 and 10, and I tried both QB64 v1.4 and 1.5.  Here is my problem:

Shell "dir /s >textfile.txt" correctly produces "textfile.txt" like I expect.

Shell "attrib /s >textfile.txt" does not produce the expected "textfile.txt"

If I just run Shell from a QB64 program and manually type "attrib /s >textfile.txt", it does correctly produce the text file.

If I make a .bat file (e.g., "createtextfile.bat") containing "attrib /s >textfile.txt" and then do Shell "createtextfile.bat", then the "textfile.txt" is created.

Any ideas on why attrib won't work from within the QB64 program?  Perhaps there is a more elegant way of getting a listing of all files in the current directory and its sub directories.  I appreciate ideas on that too!

LM

I think you can't skip the dir command ( in Shell ?). Looks like /b or /l depending what kind of listing you want, short or long ref:
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/dir

b might stand for brief or abbreviated.
« Last Edit: March 29, 2021, 05:26:18 pm by bplus »

Offline LM

  • Newbie
  • Posts: 28
    • View Profile
Re: Any ideas on SHELL behavior (dir versus attrib)?
« Reply #2 on: March 29, 2021, 05:37:07 pm »
I think you can't skip the dir command ( in Shell ?). Looks like /b or /l depending what kind of listing you want, short or long ref:
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/dir

b might stand for brief or abbreviated.

@bplus
I think dir with /b /s (and maybe /l) will work for me.  Thanks for the suggestion!  I still don't understand why attrib won't run, but those dir switches are good suggestions.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Any ideas on SHELL behavior (dir versus attrib)?
« Reply #3 on: March 29, 2021, 05:41:47 pm »
@LM are you looking for cross platform application because there are alternate ways to get dir files and folders cross platform?

Offline LM

  • Newbie
  • Posts: 28
    • View Profile
Re: Any ideas on SHELL behavior (dir versus attrib)?
« Reply #4 on: March 29, 2021, 05:56:21 pm »
@LM are you looking for cross platform application because there are alternate ways to get dir files and folders cross platform?

@bplus I am on Windows only at this time and that is where my immediate need is.  I might get on Linux in the future so feel free to share other ways (but I want to be mindful of your time and effort).  I am already using your previous suggestion.  Will save me lots of parsing.  I did not remember that dir had those switches (/b and /l).

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Any ideas on SHELL behavior (dir versus attrib)?
« Reply #5 on: March 29, 2021, 06:26:26 pm »
@bplus I am on Windows only at this time and that is where my immediate need is.  I might get on Linux in the future so feel free to share other ways (but I want to be mindful of your time and effort).  I am already using your previous suggestion.  Will save me lots of parsing.  I did not remember that dir had those switches (/b and /l).


It's no trouble for me, I've already worked through this starting from right where you are now.

The next step on Windows that SMcNeill helped me with is a permanent place to store a temp file so you can ChDir inside QB64 to any folder and still make a file (some folders you aren't allowed to write inside) for the Directory listing.

Then you want to help someone load files in Linux and you learn this method:
https://www.qb64.org/forum/index.php?topic=1511.msg122368#msg122368

That @SMcNeill also set up. (Sorry Steve, didn't mean to send a notification, just want to spell your name right, the autocompletion helps with ie or ei and double ll.)

So thank goodness for people who have come before us! :)
« Last Edit: March 29, 2021, 06:30:20 pm by bplus »

Offline zaadstra

  • Newbie
  • Posts: 78
    • View Profile
Re: Any ideas on SHELL behavior (dir versus attrib)?
« Reply #6 on: March 30, 2021, 04:32:55 pm »
If commands start acting weird then I add CMD /C to the command like this:

Code: QB64: [Select]
  1. SHELL _HIDE "cmd /c createdir.bat"

That usually solves all issues.