xteraco
|
 |
« on: November 15, 2005, 11:38:48 PM » |
|
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 
|
|
|
Logged
|
url=http://www.random-seed.net]  [/url]
|
|
|
SSC
|
 |
« Reply #1 on: November 16, 2005, 12:10:49 AM » |
|
do something like 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
|
|
|
Logged
|
url=http://www.smithcosoft.com]SmithcoSoft Creations[/url] "If you make it idiot proof, someone will make a better idiot" - Murphy's Law
|
|
|
xteraco
|
 |
« Reply #2 on: November 16, 2005, 03:07:02 AM » |
|
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?
|
|
|
Logged
|
url=http://www.random-seed.net]  [/url]
|
|
|
SSC
|
 |
« Reply #3 on: November 16, 2005, 04:09:08 AM » |
|
yet another use of the SHELL command =) 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
|
|
|
Logged
|
url=http://www.smithcosoft.com]SmithcoSoft Creations[/url] "If you make it idiot proof, someone will make a better idiot" - Murphy's Law
|
|
|
xteraco
|
 |
« Reply #4 on: November 16, 2005, 04:52:17 AM » |
|
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 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  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.
|
|
|
Logged
|
url=http://www.random-seed.net]  [/url]
|
|
|
stylin
|
 |
« Reply #5 on: November 16, 2005, 06:06:29 AM » |
|
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.
|
|
|
Logged
|
stylin:
|
|
|
xteraco
|
 |
« Reply #6 on: November 16, 2005, 06:15:37 AM » |
|
hmm, i like option 2, i'll give it a shot 
|
|
|
Logged
|
url=http://www.random-seed.net]  [/url]
|
|
|
SSC
|
 |
« Reply #7 on: November 16, 2005, 06:20:40 AM » |
|
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: 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
|
|
|
Logged
|
url=http://www.smithcosoft.com]SmithcoSoft Creations[/url] "If you make it idiot proof, someone will make a better idiot" - Murphy's Law
|
|
|
Z!re
|
 |
« Reply #8 on: November 16, 2005, 09:13:55 AM » |
|
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:
|
|
|
Logged
|
|
|
|
stylin
|
 |
« Reply #9 on: November 16, 2005, 09:26:20 AM » |
|
I deny NAME; I always option it out. It is dead to me. :normal:
|
|
|
Logged
|
stylin:
|
|
|
xteraco
|
 |
« Reply #10 on: November 16, 2005, 05:51:06 PM » |
|
wats wrong w/ name?
|
|
|
Logged
|
url=http://www.random-seed.net]  [/url]
|
|
|
Z!re
|
 |
« Reply #11 on: November 16, 2005, 06:19:49 PM » |
|
wats wrong w/ name? Nothing, stylin is just trying to save his face 
|
|
|
Logged
|
|
|
|
Rattrapmax6
|
 |
« Reply #12 on: November 16, 2005, 09:07:10 PM » |
|
wats wrong w/ name? Sorry, you logged out of AIM b4 I could think to tell you this: You are using: NAME FileName.txt, NewFileName And not: NAME FileName.txt AS NewFileName Correct? I dunno if they totaly took AS out, but the Wiki says it uses ,'s now.... :roll: :wink:
|
|
|
Logged
|
Kevin ( x.t.r.GRAPHICS) 
|
|
|
stylin
|
 |
« Reply #13 on: November 16, 2005, 09:31:13 PM » |
|
wats wrong w/ name? Nothing, stylin is just trying to save his face  The problem I have with NAME is the name. It should be RENAME, since that's what it does. I've just been optioning it out for so long I forgot existed. 
|
|
|
Logged
|
stylin:
|
|
|
Rattrapmax6
|
 |
« Reply #14 on: November 17, 2005, 12:57:43 AM » |
|
wats wrong w/ name? Nothing, stylin is just trying to save his face  The problem I have with NAME is the name. It should be RENAME, since that's what it does. I've just been optioning it out for so long I forgot existed.  SUB RENAME (FILE1 AS STRING, FILE2 AS STRING) NAME FILE1, FILE2 END SUB :roll:
|
|
|
Logged
|
Kevin ( x.t.r.GRAPHICS) 
|
|
|
|