Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
file renamer
#1
i'm tryin to make a program that takes all files in a givin directory, then renames them all... giving them a number, and leaving there extension in tact....

any help would be most appreciated Smile
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#2
do something like
Code:
DIM filename AS STRING
    Dim directory as string = "c:\temp\"    
    Dim extention as string = ".dat"

    filename = dir$(directory + "*" + extention, 32)
    count = 0
    DO
        filename = dir$("", 32)
        count=count+1
    LOOP WHILE filename <> ""
    
    filename = dir$(directory + "*" + extention, 32)
    for count2 = 1 to count
       filename = dir$("" , 32)
       SHELL "Rename" directory + filename + STR$(count2) + extention
    next
end
its not tested so I cant say for sure it will work, but the idea is sound =D
url=http://www.smithcosoft.com]SmithcoSoft Creations[/url]
"If you make it idiot proof, someone will make a better idiot" - Murphy's Law
Reply
#3
ok, here's a diff question..

lets say i have

C:\whatever\foo.jpg

and i wanna move that to

C:\newplace



how would i go about doing that?
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#4
yet another use of the SHELL command =)
Code:
directory$ = "c:\whatever\"
file$ = "foo.jpg"
new_directory$ = "C:\Newplace\"
SHELL "Copy " + directory$ + file$ + " " + new_directory$

Also you can add a new_file$ after the new_directory$ and rename the file and/or the extention to whatever you want =D
url=http://www.smithcosoft.com]SmithcoSoft Creations[/url]
"If you make it idiot proof, someone will make a better idiot" - Murphy's Law
Reply
#5
mercy, maybe i'm just an idiot... but i'm still not getting anywhere

i tried your code, but it didnt work

so, i've been trying to write my own based on what you gave me + some crap i found on the fbwiki

Code:
dim directory as string
dim filename as string
dim b as integer
dim filetype as string
dim output_directory as string


output_directory = "output"


'1.ask user what types of files to open
print "what type of files should i open?"
input filetype

'2.ask user what directory those files are stored in
print "what directory will i find these files in?"
input directory

'3. change to that dir

CHDIR directory

'4.make dir for the new files
mkdir output_directory
do
'5. open single file
filename = dir$("*.*")
  
'6. rename that file

name filename, str$(b) + filetype


'7. move renamed file into output directory



'8.delete original file


b = b + 1
CHDIR directory
loop until b = 256
end

but my stuff isnt working either, the best i've done is managed to rename the same 1 file over and over from 1 to 255 Sad

the problem seems that i can rename the file, but once the first file is renamed, i cant move on to the next.... thats where i think i'm having the trouble.... thats why i decided to have all the steps, and delete the original.
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#6
FreeBASIC has no built-in file copying/move functionality. You've got 2 options:

1. use the SHELL command to execute console-specific commands (like rename and move for DOS/Windows).
2. OPEN the file, copy it by creating another file in the destination directory, then KILL the original file.
stylin:
Reply
#7
hmm, i like option 2, i'll give it a shot Big Grin
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#8
well I wrote one that works to do what you want but for some reason it can't copy from directories outside of where it is run. Its prolly something small but here is the code that will work from the directory it is run:
Code:
Dim directory as string
Dim output_directory as string
Dim filename as string
Dim filetype as string*4
Dim new_filename as string
Dim count as integer
output_directory = "output\\"

count = 0

screen 15,,,

print "what type of file should I open?(.xxx)"
input filetype

print "what directory will i find these files in?"
input directory

mkdir output_directory

filename = dir$(directory + "*" + filetype , 32)

do

filename = dir$("", 32)


SHELL "Copy " + directory + filename + " " + output_directory + str$(count) + filetype
print filename+" Copied succesfully..."

count = count + 1

loop until filename = ""
sleep
url=http://www.smithcosoft.com]SmithcoSoft Creations[/url]
"If you make it idiot proof, someone will make a better idiot" - Murphy's Law
Reply
#9
Quote:FreeBASIC has no built-in file copying/move functionality. You've got 2 options:

1. use the SHELL command to execute console-specific commands (like rename and move for DOS/Windows).
2. OPEN the file, copy it by creating another file in the destination directory, then KILL the original file.
NAME
:roll:
Reply
#10
I deny NAME; I always option it out. It is dead to me. :normal:
stylin:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)