Ahk Scrpit that copy text from notepad and rename files Topic is solved
Ahk Scrpit that copy text from notepad and rename files
Hi,
I am currently working on script that will copy text from notepad and rename all the files accordingly to the notepad names.
naming can be like
Abc_abc_aaa
If anyone can guide me on this it will very Helpful.
Thanks
I am currently working on script that will copy text from notepad and rename all the files accordingly to the notepad names.
naming can be like
Abc_abc_aaa
If anyone can guide me on this it will very Helpful.
Thanks
Re: Ahk Scrpit that copy text from notepad and rename files
So it is something like this take names from notepad and renames the file
I think i can try using Filemove for renaming but i not sure how to store notepad file names (I can add Number 1,2,3 before name if that helps with the logic to store names)
I think i can try using Filemove for renaming but i not sure how to store notepad file names (I can add Number 1,2,3 before name if that helps with the logic to store names)
Re: Ahk Scrpit that copy text from notepad and rename files
Code: Select all
dir := A_ScriptDir
ControlGetText, list, Edit1, ahk_exe notepad.exe
For fileNum, fn in StrSplit(list, "`r`n") {
SplitPath, fn,,, ext, fnBare
FileMove, %dir%\%fn%, %dir%\%fnBare%-%fileNum%.%ext%
}
MsgBox, 64, Done, Done!
Re: Ahk Scrpit that copy text from notepad and rename files
Thanks for help But the code is not working i have checked it is taking the name from notepad but unbale to rename the file
Re: Ahk Scrpit that copy text from notepad and rename files
You can display the values of the variables in the loop, so that you know what they are. That will enable you to debug your script. FileExist will tell you whether the file exists. The script worked in my test, but I used my Notepad file rather than yours, which is not posted.
Re: Ahk Scrpit that copy text from notepad and rename files
Hi,
Yes I have check by display all the values And i found it is not taking path of images that is available in folder generally we can find that using "A_LoopFilePath" but since we are not using loop i cannot use that. That is why FileMove is not working
Since there is no "SourcePattern".
Also This line
Is it suppose to remove the number. because the Output i get from that is "C:\root\1 Abc_aaa-1.png"
%fnBare% = Name from notepad i.e 1 Abc_aaa
%fileNum%.%ext% = 1.png
Yes I have check by display all the values And i found it is not taking path of images that is available in folder generally we can find that using "A_LoopFilePath" but since we are not using loop i cannot use that. That is why FileMove is not working
Since there is no "SourcePattern".
Also This line
Code: Select all
FileMove, %dir%\%fn%, %dir%\%fnBare%-%fileNum%.%ext%
%fnBare% = Name from notepad i.e 1 Abc_aaa
%fileNum%.%ext% = 1.png
Re: Ahk Scrpit that copy text from notepad and rename files
You can post your complete script, your Edit1 contents or sample file, and the path to the directory where these files reside. Include a description of how each file should be renamed.
When you used MsgBox to display the values of dir and fn in the script that I posted, what did you see?
When you used MsgBox to display the values of dir and fn in the script that I posted, what did you see?
Re: Ahk Scrpit that copy text from notepad and rename files
As i have mentioned I am looking to rename file based on notepad file
After rename result should be something like this From this code
From %List% i am getting name from notepad
Edit1 is coming blank
%dir% = C:\Users\New folder\New folder
%fn% = 1 Abc_test.png
%fnBare% = 1 Abc_test
fileNum = 1,2,3
ext = .png
So the script will takes names from notepad and rename the file in the folder one by oneAfter rename result should be something like this From this code
Code: Select all
dir := A_ScriptDir
ControlGetText, list, Edit1, ahk_exe notepad.exe
For fileNum, fn in StrSplit(list, "`r`n") {
SplitPath, fn,,, ext, fnBare
FileMove, %dir%\%fn%, %dir%\%fnBare%-%fileNum%.%ext%
}
MsgBox, 64, Done, Done!
Edit1 is coming blank
%dir% = C:\Users\New folder\New folder
%fn% = 1 Abc_test.png
%fnBare% = 1 Abc_test
fileNum = 1,2,3
ext = .png
Re: Ahk Scrpit that copy text from notepad and rename files
Is Notepad the name of your saved text file, or are you saying that you have the Microsoft Notepad program open, and you have text displayed in that program?
Re: Ahk Scrpit that copy text from notepad and rename files
I have Microsoft Notepad program open and have all text name as shown in image.
Re: Ahk Scrpit that copy text from notepad and rename files
Hmm. Let's back up and just see if we can get the text.
Is more than one instance of Notepad open?
Code: Select all
#IfWinExist ahk_exe notepad.exe
F3::
ControlGetText, list, Edit1
MsgBox, 64, List, %list%
Return
#IfWinExist
Re: Ahk Scrpit that copy text from notepad and rename files
Yes I am able to get the text and no there is only one instance of notepad is running.
Re: Ahk Scrpit that copy text from notepad and rename files
OK. I am confused. You indicated earlier, "Edit1 is coming blank". What did you mean by that, and how did you determine it? Are you testing a script that is not actually posted here? If so, please post it below.
Re: Ahk Scrpit that copy text from notepad and rename files
ohh sorry Edit1 is still coming blank I meant list is showing all the names.
Edit1 Input
Re: Ahk Scrpit that copy text from notepad and rename files
You have highlighted the bug in your script, but you have not yet provided a written description of how to rename your files-- i.e., what the new names should be. "naming can be like Abc_abc_aaa" provides one file name but does not explain anything.
Re: Ahk Scrpit that copy text from notepad and rename files
So i was thinking like this first image that is in the folder to be renamed with first name in notepad and so on.
Lets say first image name is like this
"Knight_Templer"
So replace this name to the name from notepad like 1 Rename_Test. so final name would be "Rename_Test"
Lets say first image name is like this
"Knight_Templer"
So replace this name to the name from notepad like 1 Rename_Test. so final name would be "Rename_Test"
Re: Ahk Scrpit that copy text from notepad and rename files
As you describe it, the first line in Notepad should correspond to the first file in your folder. What is your description of how to get from that Notepad line to your final file name? I see an example but not a description of the process.
Re: Ahk Scrpit that copy text from notepad and rename files
From the Code you have provided in %fn% we can able to get names from notepad and i know I can get file name by A_LoopFilePath but i not sure how to incorporate these 2 output in one place.
Re: Ahk Scrpit that copy text from notepad and rename files
You must have an idea of how you get from "1 Rename_Test" to "Rename_Test", right? Remove one digit? Skip text before the first space? Other?