file and folder names

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

file and folder names

07 Mar 2018, 14:00

Hi guys,
This Script for display a list of file and folder names

Code: Select all

Global strFile := A_ScriptDir . "\Liste.txt"
FileDelete, %strFile%
FileSelectFolder, dir, , 3
if(dir) {
	Sub(dir . "\*.*", 0)
	run, %strFile%
	ToolTip,
}
Return
Sub(strDir, intLevel) {
	ToolTip, Level #%intLevel% %strDir%
	Loop, %intLevel%
		strTabs := strTabs . A_Tab
	Loop, %strDir%, 2 ; scan folders
	{
		FileAppend, %strTabs%\%A_LoopFileName%`n, %strFile%
		Sub(A_LoopFileFullPath . "\*.*", intLevel + 1) ; Recurse to subdirectory
	}
	Loop, %strDir%, 0 ; now scan files only
	{
		FileAppend, %strTabs%\%A_LoopFileName%`n, %strFile%
	}
}
Is there a way to hide the files extintions and the slash sign from the names?
I mean: How to display files and folders names without:
1- File extension
2- this sign " \ "
Any help would be greatly appreciated
Thanks in advance
Last edited by asad41163 on 12 Mar 2018, 12:02, edited 2 times in total.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: file and folder names

07 Mar 2018, 14:06

SplitPath
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: file and folder names

07 Mar 2018, 14:42

Code: Select all

SplitPath, FullFileName, name
I tried and could not,, please do it for me.
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: file and folder names

08 Mar 2018, 05:06

Please teach me how to do this
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: file and folder names

08 Mar 2018, 06:58

Code: Select all

path := "https://msdn.microsoft.com/en-us/library/dn792258(v=vs.85).aspx#_hmm_multimedia_audio_visual"	; split URL
	SplitPath, path , OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
	MsgBox %	OutFileName		"`n"
			.	OutDir			"`n"
			.	OutExtension	"`n"
			.	OutNameNoExt	"`n"
			.	OutDrive
	path :=	"C:\Program Files\AutoHotkey\_Archive AHK 1.1"												; split local path
	SplitPath, path , OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
	MsgBox %	OutFileName		"`n"
			.	OutDir			"`n"
			.	OutExtension	"`n"
			.	OutNameNoExt	"`n"
			.	OutDrive		
	Return
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: file and folder names

08 Mar 2018, 07:18

If you want a quick and easier way (For more advanced programmers) with some pretty simple edits for your code (And if you understand how to use objects in programming) Then use this function:

Code: Select all

Path := "https://msdn.microsoft.com/en-us/library/dn792258(v=vs.85).aspx#_hmm_multimedia_audio_visual"	; split URL
X := SplitPath(Path) ; This pushes the path that you set into the object for which you can call all of the individual variables from the object.

MsgBox %	X.FileName		"`n"
		.	X.Dir			"`n"
		.	X.Extension		"`n"
		.	X.NameNoExt		"`n"
		.	X.Drive

path :=	"C:\Program Files\AutoHotkey\_Archive AHK 1.1" ; split local path
Y := SplitPath(Path) ; Same thing here.
MsgBox %	Y.FileName		"`n"
		.	Y.Dir			"`n"
		.	Y.Extension		"`n"
		.	Y.NameNoExt		"`n"
		.	Y.Drive
Return


/*
	Object := SplitPath(File)

	File - [In, filepath]
		: The file or URL to parse from.
	Object - [Out, object]
		: The object to push all of the variables out of.

	============================================================
	Var := SplitPath(File).Type

	File - [In, filepath]
		: The file or URL to parse from.
	Type - [In, var]
		: The specific variable to use when calling the function
			- Available types include:
				FileName
				Dir
				Extension
				NameNoExt
				Drive
*/

SplitPath(File) {
	SplitPath, File, FileName, Dir, Extension, NameNoExt, Drive
	Return, {FileName: FileName, Dir: Dir, Ext: Ext, NameNoExt: NameNoExt, Drive: Drive}
}
This may be a bit advanced but it still works.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: file and folder names

19 Mar 2018, 13:40

Please, any body do it for me.
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: file and folder names

20 Mar 2018, 05:10

please
What is wrong with this code?

Code: Select all

Global strFile := A_ScriptDir . "\Liste.txt"
FileDelete, %strFile%
FileSelectFolder, dir, , 3
if(dir) {
	Sub(dir . "\*.*", 0)
	run, %strFile%
	ToolTip,
}
Return
Sub(strDir, intLevel) {
	ToolTip, Level #%intLevel% %strDir%
	Loop, %intLevel%
		strTabs := strTabs . A_Tab
	Loop, %strDir%, 2 ; scan folders
	{
		FileAppend, %strTabs%\%A_LoopFileName%`n, %strFile%
		Sub(A_LoopFileFullPath . "\*.*", intLevel + 1) ; Recurse to subdirectory
	}
	Loop, %strDir%, 0 ; now scan files only
	{
		FileAppend, %strTabs%\%A_LoopFileName%`n, %strFile%
		SplitPath, FullFileName, name		 "`n"
		SplitPath, FullFileName, nameNoExt		"`n"
	}
}
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: file and folder names

20 Mar 2018, 16:51

Perhaps you should deconstruct your code and check smaller code units if they do what you want... I think to most people it won't be clear on first sight what you want to achieve, anyway. A description of your goal might be useful. I guess, it is some kind of a visual representation of a directory and file structure - you could show an example what you want to have in the end...

At least, the SplitPath part doesn't make sense like this. You don't assign any contents to FullFileName, and it is not one of the built-in variables - you might want one of these instead: https://autohotkey.com/docs/commands/Lo ... _File-Loop - therefore name and nameNoExtwill be empty, too. But you don't even use these variables after that... apart from that, I don't think you can add a newline this way in this step (this is not the msgbox command)

Perhaps try first to understand Splitpath by working with the examples provided here and in the docs.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AHK_user and 263 guests