Author Topic: Hope you will pardon a possibly dumb question regarding simple file operations  (Read 2989 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
I wrote a program that performs a LOT of operations by running Windows command line utilities via SHELL commands. Because of this, I have simply been doing many basic file operations like copying and moving files using SHELL commands along with Windows COPY, MOVE, ROBOCOPY, etc.

However, it just seemed odd to me lately that I'm not seeing equivalent commands for these simple operations in QB64. It's entirely possible that I'm simply missing something. Could someone just tell me if I'm being obtuse here or is running commands like COPY, MOVE, etc. via SHELL the normal way to perform these operations?

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
I use SHELL, too, but the scripts for copy and move in QB64 are fairly easy, and once in awhile I write them in a routine...

I use...


_DIREXISTS() to confirm the input destination directory exists for a move.
_FILEEXISTS() to confirm the file input exists, and to control overwrite options  if the file already exists in the destination folder.

The COPY and MOVE part...

' Where myfile$ is the folder and name of the file to copy/move and myfilecopy$ is the folder and name of the file to b placed in the destination folder.
OPEN myfile$ FOR BINARY AS #1
x$ = SPACE$(LOF(1))
GET #1, , a$
CLOSE #1

OPEN myfilecopy$ FOR BINARY AS #1
PUT #1, , a$
CLOSE #1

For MOVE, just add KILL myfile$

Add more bells and whistles as needed for overwrite warnings, etc.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
You can also use NAME to move files.

Code: QB64: [Select]
  1. NAME “c:/one folder/file.bas” AS “c:/different folder/file.bas”
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Fantastic. Thanks to both of you. Extremely helpful!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Hanness,

A few pointers on "dumb questions"....

1. If the question is relevant to "you" and the problem that you have, any question that leads you to a solution, can 'never' be dumb.
2. It's not logical to seek forgiveness 'before' the event. Never apologise for something that you have not done.
3. All of the responses to your question 'never' indicated that it was dumb. They didn't reply as if it was, so neither should you ask, as if it was.
4. We are all here to help. Ask away...
Logic is the beginning of wisdom.