Poll of the Day > Would this be easy for a novice to code?

Topic List
Page List: 1
NeoSioType
04/13/17 8:06:22 PM
#1:


It's time consuming to do manually so I need a small program that will allow me to sort files that have random alphanumeric names (and dates) by renaming the files to have numeric order. The appropriate order is known from a list so hopefully it's as simple as copy/pasting the list and assigning numbers.
... Copied to Clipboard!
Kyuubi4269
04/13/17 8:10:29 PM
#2:


How is the list formatted? Because you'll have more trouble than it's worth potentially.
---
RIP_Supa posted...
I've seen some stuff
... Copied to Clipboard!
knivesX2004
04/13/17 8:14:38 PM
#3:


NeoSioType posted...
It's time consuming to do manually so I need a small program that will allow me to:

sort files that have random alphanumeric names (and dates) by renaming the files to have numeric order.

The appropriate order is known from a list so hopefully it's as simple as copy/pasting the list and assigning numbers.


Can you give me an example?
Is it something like this?

Files ------------ list/code----
Knives.jpg ---- > 1 ---> 1.jpg
SBAllah.avi ----> 3 ---> 3.avi
CJayC.flac ----> 2 -----> 2.flac
Harambe.meme ---> 4 ----> 4.meme

final result
1.jpg
2.flac
3.avi
4.meme

???
... Copied to Clipboard!
NeoSioType
04/13/17 8:27:50 PM
#4:


The list is line by line in notepad. However I have to delete the rest of the URL to get the file name.

Not too much trouble. Still less work than searching and renaming everything manually.

Then again I'm a novice so this might be a learning opportunity or goal.

The files are all jpg and the list is in order. Example:

GUI40G1.jpg ------>1
AU640JQ.jpg ------>2
U678FG0.jpg ------>3

All I have to do to find the number-name is number them by line.
... Copied to Clipboard!
Kyuubi4269
04/13/17 8:36:10 PM
#5:


So you want a script that changes the image names in a predetermined folder to their corresponding line count in the accompanying txt file?
---
RIP_Supa posted...
I've seen some stuff
... Copied to Clipboard!
NeoSioType
04/13/17 8:39:31 PM
#6:


Yeah, that would work nicely.
... Copied to Clipboard!
Thunder_54
04/13/17 8:41:49 PM
#7:


NeoSioType posted...
GUI40G1.jpg ------>1
AU640JQ.jpg ------>2
U678FG0.jpg ------>3

All I have to do to find the number-name is number them by line.


I'd suggest changing the format to :

GUI40G1.jpg 1
AU640JQ.jpg 2
U678FG0.jpg 3

It's easier to parse.

Python will make quick work of this job for you.

You'll need to research the file functions and the system functions for dealing with directories/file renaming.

EDIT: although since they're already in order, you don't even really need the number.
---
http://i.imgur.com/Mi1LkTl.jpg
"It's all consensual" - Thunder
... Copied to Clipboard!
NeoSioType
04/13/17 8:54:40 PM
#8:


Ah, Python. If I knew that I could play around in the Blender console.

Thanks for the direction.
... Copied to Clipboard!
Kyuubi4269
04/13/17 9:00:00 PM
#9:


I don't know the language you're familiar with and my coding knowledge is exclusively from automating MUDs but you could do something like:

referenceFile = "C:/User/Admin/Desktop/imageFileOrder.txt"
sortFolder = C:/User/Admin/Desktop/Porn"
lineCount = 1
currentLine = nil

function renameAll()

getLine(referenceFile, lineCount)
currentLine = getLine()
rename(sortFolder.."/"..currentLine, lineCount..".jpg")

lineCount = lineCount+1

if currentLine != nil then
renameAll()
end
end

renameAll()


Convert the logic appropriately to the language you use.
---
RIP_Supa posted...
I've seen some stuff
... Copied to Clipboard!
AwesomeTurtwig
04/13/17 9:01:09 PM
#10:


For 50 bucks all give you a shiny python script.
---
... Copied to Clipboard!
Thunder_54
04/13/17 9:23:03 PM
#11:


AwesomeTurtwig posted...
For 50 bucks all give you a shiny python script.

Pfft.

Don't pay for this, TC. This is like 20 lines of code AT MOST. probably closer to 10.
---
http://i.imgur.com/Mi1LkTl.jpg
"It's all consensual" - Thunder
... Copied to Clipboard!
thecolorgreen
04/13/17 9:25:49 PM
#12:


AwesomeTurtwig posted...
For 50 bucks all give you a shiny python script.


I'll do it for $49.95
---
:wq
... Copied to Clipboard!
knivesX2004
04/13/17 9:30:38 PM
#13:


TC, I'm not sure how familiar with coding you are so ignore this if you already know it.
You should use this as a learning experience.
One of the main things in CS is Divide and Conquer.
Break down everything you need to do into a list.

First I need to... load in the text file.
Then I need to... load the folder containing the files.
Then I need to... etc etc.

Once you have that you should be able to pseudo code your way to a logical program and then from there you can transform it into code one step at a time.
... Copied to Clipboard!
Sahuagin
04/13/17 9:34:33 PM
#14:


can probly do it in one line at windows command prompt (remember that if you put it in a .bat file you have to double all the % signs)

closest I got so far is:

for /f "tokens=1,2 delims= " %a in ('type data.txt') do rename %a %b.jpg

this is assuming a data file that looks like:

asdf.jpg 1
fdsa.jpg 2
somethingelse.jpg 3


tricky thing with this is that it's hard to undo if you get it wrong. well, actually no it isn't, because you can just swap the arguments to rename.

explanation:

for /f loops over things (type for /? to see help)

"tokens=1,2 delims= " says we want the first and second item after splitting with space

not sure how it works exactly, but using %a means that the tokens will be in %a %b %c, etc... using a different letter doesn't work

('type data.txt') allows for to loop over each line in the file. a really useful one is ('dir /ad/b') which lists all directories in a plain format

rest is self explanatory
---
... Copied to Clipboard!
Sahuagin
04/13/17 9:48:22 PM
#15:


actually, the ('type data.txt') can be reduced to just (data.txt), no reason to run the type command for will already just process a text file that way

for /f "tokens=1,2 delims= " %a in (data.txt) do rename %a %b.jpg

note, though that windows might not sort files numerically, even if you number them 1, 2, 3, 4, 5, etc. they will still be sorted alphabetically, where "10" is alphabetically before "2", etc.

testing this out, doesn't seem to be an issue in windows 7, which is not something I knew. in the event that you had that problem, you can get around it by using leading zeros.
---
... Copied to Clipboard!
AwesomeTurtwig
04/15/17 10:21:21 PM
#16:


thecolorgreen posted...
AwesomeTurtwig posted...
For 50 bucks all give you a shiny python script.


I'll do it for $49.95

My offer is now $49.90
---
... Copied to Clipboard!
aiyobro
04/16/17 1:30:10 AM
#17:


put the file names in an array sort the array then rename the files according to the index in the array

easy if you know how to rename files
---
"That's a Blu Ray player, not a PS3, that's why it can't read the game"-rswsc0407
... Copied to Clipboard!
Topic List
Page List: 1