Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
file renamer
#21
to tell the truth, last thing i tried was stylin's last example, the one he said works...

i tried it, and what it did was it renamed a single file i guess, so when i looked in the output dir, all i saw was 1 file... 1.jpg or 0.jpg i dont remember... but thats all that was there

sinse then i havent really messed w/ it..lol, i'm thinkin bout workin on it a little today, because i'm trying to use it to put a bunch of pics on my webpage and organise them...

another thing i was gonna use it for is... . well, heres a strory

for a while i was usin linux cause my windows box crashed, and i used linux to backup my old data, the burning software i use in windows uses joilet burning format, wich keeps filenames looking the same when there on disk... well, the burner in linux didnt accept burning with the joliet burning format and only supported some iso FS burning .... so when i burned all my data with that format, i lost the names of most of my mp3's... and some of them are so rare, i cant find the names to em on the web

the name loooks like I___am_a.....mp3

it really sucks! so what i'm wanted to do is use the file renamer to rename my songs as well, i couldnt do it by hand cause were talkin about 400 or so songs

so in short, no i havent gotten it to work yet... and i'm probably gonna haggle w/ it a bit today and see what happens
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#22
Xteraco,

I couldn't figure out how the DIR$ worked in FB, so I put together a solution (see below) that works in QB and should also work in FB.

I added checking and validation of the what you called "filetype". I also made sure that this filetype exists in the source directory.

I changed the output directory to just "output" instead of "output\\"., and I deleted the MKDIR of this directory which makes testing a pain. I was going to have the user provide the name of the output directory, but I had all kinds of trouble trying to validate it. So, I basically left it like you had it.

I added an audit trail file called "auditfil" so you can review what files were renamed to what.

I tested this version, so it should do what you originally intended. If not, I'll fix it for you. Regards.........
Code:
defint a-z
cls
count = 0
dummy$ ="!!!dummy"
outdir$="output"

getft:
print "What type of file (file extension .xxx) should be used";
input filetype$
if instr(filetype$,".")<>1 or len(filetype$)<2 or len(filetype$)>4 then
   print "ERROR: invalid file extension. Must be a dot + 1-3 characters."
   goto getft
end if

print
print "Enter path of the directory where these files can be found";
input dirin$
bkslash$="\"
'Note: dirin$ will be null when specifying default directory,
'      and dirin$ can be "\" when specifying root directory.
if dirin$="" or dirin$="\" then bkslash$=""
s$="DIR "+dirin$+bkslash$+"*"+filetype$+"/B>"+dummy$
shell s$

open dummy$ for input as #1
'Note: if above DIR did not find files, dummy$ file will be a zero-length-file,
'      which will give an immediate EOF.
if eof(1) then
   print "FATAL ERROR: no files with "+filetype$+" found on directory "+dirin$
   GOTO ENDOFJOB
end if

open "auditfil" for output as #2
do while not eof(1)
   line input #1,f$
   count=count+1
   s1$="COPY "+dirin$+bkslash$+f$+" "+outdir$+"\"+ltrim$(str$(count))+filetype$
   s$=s1$+">nul"
   shell s$
   print #2,s1$
loop

s$="DEL "+dirin$+bkslash$+"*"+filetype$  'Delete original files
shell s$

ENDOFJOB:
close
kill dummy$
system
*****
Reply
#23
DIR()
Code:
mask$ = "*.*"
t$ = DIR$( mask$ )
do while t$ <> ""
  print "File found: "+t$
  t$ = DIR$()
loop

Enjoy..
Reply
#24
Xteraco,

I forgot to mention that for my program above you need to create (make) the directory "output" before the first time you run it. This output directory must be a subdirectory of the default directory.
*****
Reply
#25
In FB, creating a dir can be achieved with: MKDIR()
Also, MKDR never "fails" unless you specify FB to use error checking etc in the compiled file..

Basically, just stick a MKDIR() in there, and the program will always work, if the dir already exist or if it does not already exist..
Reply
#26
Quote:In FB, creating a dir can be achieved with: MKDIR()
Also, MKDR never "fails" unless you specify FB to use error checking etc in the compiled file..

Basically, just stick a MKDIR() in there, and the program will always work, if the dir already exist or if it does not already exist..
Z!re,

If I interpret what you say correctly, then I'm not convinced that MKDIR should never fail.
1) If the directory already exists, then it's a good idea not to fail. QB will fail. But there's no harm done if you don't fail.

2) If the directory name or path\directory is of invalid format or has invalid characters, then the MKDIR should fail, otherwise the program will think it now has that directory available. Another poor, off-the-cuff decision in FB.


Xteraco,

If you're using FB, then take Z!re's advice and stick in the MKDIR. Since I'm running QB, I can't do that.
*****
Reply
#27
MkDir() can fail; if it does fail, you are expected to handle this - either by using the traditional On Error Goto ... or by checking the return value of MkDir:

Code:
if mkdir("C:\blah") = 0 then
    print "success"
else
    print "failure"
end if
Reply
#28
DrV,

Ah yes, that makes more sense. Thanks.
*****
Reply
#29
What's the return value for MkDir(...) ? Is it safe to use this,
Code:
function some_function( directory as string ) as integer
      ...
   if( mkdir( directory ) ) then
      return -1
   end if
      ...      '' assume directory was created
end function
or are there multiple error codes ?
stylin:
Reply
#30
If you dont check the return value, no harm done.. if you cant create the directory, either the medium is write protected, or the directory already exist..

However, I use mkdir alone, no error checking, and noone has reported any problems..
If people write protect the folder they install my programs too, they got worse problems than my program not working Tongue (Such as being silly/stupid)

99% of the time when MKDIR() "fails" it "fails" because the directory already exist, and as such, it cant really be counted as a fail.. really..


In short, if you just want to creat a dir, and only care that the dir exist, dont bother to check if mkdir worked or not..
Problems could be write protection, out of diskspace or the dir already exist..

The last one is silly to fail on..
The first two will fail later if you try to create files, and checking for file integrity is something you should do, and which is easier to do..
(Even if mkdir succeeds there might not be any diskspace left to make the actuall files, etc)


If you want to be really anal, you should FIRST list all dirs in the folder, if a dir does not exist, create it, check for all errors, verify integrity.. then move on..

Or, you could just create the dir and ignore any errors related to it, as 99% of the errors are caused by the dir already exists Tongue
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)