Author Topic: Moving directories into directory slots  (Read 5037 times)

0 Members and 1 Guest are viewing this topic.

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Moving directories into directory slots
« on: July 13, 2019, 10:36:04 am »
I was going out of my mind figuring this one out.  "Name as" wasn't going to work.  Plus you must follow cmd.com rules in dos.  As I was asking a question of the group to post.  It hit me, with another way about it.  Command com "move" was the way to do it.  But simple straight ahead usage would always fail.  So I became inventive with CHDIR and "." and ".."

Some basic rules to my game.  A directory on a drive has 27 entries.  Named dirs are A to Z and 0-9.  27 in all.  I want to slot (dirs) into the 27 directories.  All directories exist in the same folder before the program is executed.   The directories name can contain "spaces" but not be one character long.  The program can be executed twice without faulting.  The program will not overwrite a name that does exist in the sub dir.  It does not move.  When you have over 1 million media files in over 50K directories.  Sorted slot trees is the only way to go.

Important bits: listtxt$ location to store a temp file of dirs.  rootdir$ Full path of media directory.  Must contain "\" at the end.  Or change the program chdir rootdir$+whereto$
Please be kind.  The program could have been more elegant.  Using things like freehandles for file open and such.  it's all based on my trash80 days.  Very K.I.S.S.
I thought of using "system" to exit.  But it would have flashed by and be a blur.  So I let it fall thru and stop.  So at least you can see something.

Code: QB64: [Select]
  1. q$ = CHR$(34)
  2. rootdir$ = "f:\HPics\Hentai Doujin\"
  3. listtxt$ = "c:\qb64\thelist.txt"
  4.  
  5. CHDIR rootdir$
  6. SHELL "dir /o/b > " + listtxt$
  7.  
  8. OPEN listtxt$ FOR INPUT AS #1
  9.  
  10.     LINE INPUT #1, d$
  11.     IF LEN(d$) = 1 THEN GOTO next_loop
  12.     IF d$ = "0-9" THEN GOTO next_loop
  13.  
  14.     whereto$ = LEFT$(d$, 1)
  15.  
  16.     IF whereto$ >= "0" AND whereto$ <= "9" THEN whereto$ = "0-9"
  17.  
  18.     CHDIR rootdir$ + whereto$
  19.  
  20.     exe$ = "move " + q$ + "..\" + d$ + q$ + " " + q$ + "." + q$
  21.  
  22.     PRINT exe$
  23.     SHELL _HIDE exe$
  24.  
  25.     CHDIR rootdir$
  26.  
  27.     next_loop:
  28.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Moving directories into directory slots
« Reply #1 on: July 13, 2019, 11:10:15 am »
Well, congrats; now you're starting to "think" like a programmer. At least I've always considered the ability to see different possibilities as an asset. Now, you could have used NAME AS, but my hunch is you were not naming the full drive name and directory path in your code; but, I can't say I remember about NAME AS working across drives. It should, but I don't have a usb stick handy to test that out right now. I also cannot recall if NAME AS has any hang ups about spaces in a directory path. We can overcome that by including the directory path in quotes with: "driveletter:\" + CHR$(34) + "pathname" + CHR$(34) + "filename"

So, the space in your f-drive path might be causing NAME AS to fail.

You might want to back up a copy of your file and try: NAME "myfile.txt" AS "f:\HPics\" + CHR$(34) + "Hentai Doujin" + CHR$(34) + "\myfile.txt"

I also noticed you used GOTO a couple of times, which can get to be a problem when you start coding several hundreds of lines. An IF/THEN block is what I generally used to avoid GOTO whenever possible and practical...

Code: QB64: [Select]
  1. q$ = CHR$(34)
  2. rootdir$ = "f:\HPics\Hentai Doujin\"
  3. listtxt$ = "c:\qb64\thelist.txt"
  4.  
  5. CHDIR rootdir$
  6. SHELL "dir /o/b > " + listtxt$
  7.  
  8. OPEN listtxt$ FOR INPUT AS #1
  9.  
  10.     LINE INPUT #1, d$
  11.  
  12.     IF LEN(d$) = 1 OR d$ = "0-9" THEN ' <<< START OF BLOCK IF STATEMENT
  13.  
  14.         whereto$ = LEFT$(d$, 1)
  15.  
  16.         IF whereto$ >= "0" AND whereto$ <= "9" THEN whereto$ = "0-9"
  17.  
  18.         CHDIR rootdir$ + whereto$
  19.  
  20.         exe$ = "move " + q$ + "..\" + d$ + q$ + " " + q$ + "." + q$
  21.  
  22.         PRINT exe$
  23.         SHELL _HIDE exe$
  24.  
  25.         CHDIR rootdir$
  26.  
  27.     END IF  ' <<< END OF BLOCK IF STATEMENT
  28.  

Sorry I'm not able to test and verify. I have some outdoor work I have to get done before the sun pops up. I miss my younger days, when I had all this stuff in MY memory!

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

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Moving directories into directory slots
« Reply #2 on: July 13, 2019, 12:19:12 pm »
Yea, I saw the two goto's for "or" simplification.  After the fact.  And changed my own and not this example.
I only used the goto's as a means to remember where the do/loop block starts and stops.
Using loop after a then is insane.  I've had used 5 nested do loop's in one shot, with exit do's to boot.
Little whoopsy on your part the "or" simplify reversed the state logic in reference to the do loop.  So I took
advantage and also fixed a unix throwback error windows can do as well.  re: "space" as the first of or several
characters in a name. That problem would have been a real foobar.

Just an after thought.  If you run this on a true unix environment of qb64.  Slashes reverse and Case state
become important for dir names.  Because "aAa" is different than "AAA" or "AaA" and " aAa"

Code: QB64: [Select]
  1. q$ = CHR$(34)
  2. rootdir$ = "f:\HPics\Hentai Doujin\"
  3. listtxt$ = "c:\qb64\thelist.txt"
  4.  
  5. CHDIR rootdir$
  6. SHELL "dir /o/b > " + listtxt$
  7.  
  8. OPEN listtxt$ FOR INPUT AS #1
  9.  
  10.     LINE INPUT #1, d$
  11.     IF LEN(d$) = 1 OR d$ = "0-9" THEN
  12.         PRINT "Avoiding " + d$
  13.  
  14.     ELSE
  15.  
  16.         whereto$ = LEFT$(d$, 1)
  17.  
  18.         IF whereto$ = " " THEN
  19.             PRINT "Space can't be first character in directory name"
  20.             PRINT "--->" + d$ + "<---"
  21.             END
  22.         END IF
  23.  
  24.         IF whereto$ >= "0" AND whereto$ <= "9" THEN whereto$ = "0-9"
  25.  
  26.         CHDIR rootdir$ + whereto$
  27.  
  28.         exe$ = "move " + q$ + "..\" + d$ + q$ + " " + q$ + "." + q$
  29.  
  30.         PRINT exe$
  31.         SHELL _HIDE exe$
  32.  
  33.         CHDIR rootdir$
  34.  
  35.     END IF
  36.  
« Last Edit: July 13, 2019, 12:38:07 pm by doppler »

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Moving directories into directory slots
« Reply #3 on: July 13, 2019, 01:05:20 pm »
used NAME AS, but my hunch

name as's rule "must follow dos rules of REN statement".  Unlike in unix/linux ren in dos can't rename across directories or drives.
Also move in dos tends to barf at renaming.  Unlike unix/linux.  But then again unix/linux is so textual based.  Throwback
to AT&T teletype days.

So I got something that eluded me for so long that works.  Hope someone else benefits too.
« Last Edit: July 13, 2019, 01:07:43 pm by doppler »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Moving directories into directory slots
« Reply #4 on: July 13, 2019, 01:36:48 pm »
Big oops, actually. I intended to either change the = to <>, and change OR to AND: IF LEN(d$) <> 1 AND d$ <> "0-9" THEN ...or add ELSE, to the existing IF/THEN statement, but then I  neglected to do either before posting the code. My bad for muti-tasking with outdoor activities! I read someplace that guys do poorly at multi-tasking. I'm pretty sure Tim Allen got his whole guy bit from me, but I digress....

Anyway, did you try the NAME AS with quotes?

BTW, one difference between NAME AS and MOVE is that MOVE will overwrite a file, and NAME AS will fail if a file with the same name already exists in the drive / directory you are attempting to move it to. _FILEXISTS and _DIREXISTS are helpful in QB64 to prevent such errors, without the need to build an error trapping routine.

http://www.easydos.com/move.html

Sorry about the logic slip. And now, back to the damn yard!

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

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Moving directories into directory slots
« Reply #5 on: July 13, 2019, 03:36:33 pm »
enjoy the outdoors.

Tried your original way of quotes.  NG.
also
name will not go across drives.  "bad/path error"
name won't work if you use specific paths in the command re: name "e:\t2\mydir" as "e:\t2\Hentai Doujin\mydir"

will work only if
chdir "e:\t2"  <-- changes based on nest levels.
f$ = "e:\t2\Hentai Doujin\"  <-- this one too.
NAME "mydir" AS f$ + "mydir"

Go figure i can use strings and literal with chdir.  But not just literal.
Haven't tried but I think I can only get away bumping one level change.  Won't want to chance it anyways.

Have a good time remaining.  My vaction time ends on Monday too.

ps.
I will keep the original way using shell _hide and move.  I already do checking elsewhere for dupe dir's.
Plus less I forget, dos "move" won't happen if it's wrong.  I will still be looking at a non-moved dir.
See it and then slap myself in the head and say.  "forgot to do that other check program first"
I also changed output to a console window, so I can see where the 100's of dirs went.
« Last Edit: July 13, 2019, 03:40:19 pm by doppler »