Many will found that this is repeating questions but i have gone through all the questions before asked about this topic but none worked for me.
I want to print full path name of the certain file format using ls command so far i found chunk of code that will print all the files in the directory but not full path.
for i in io.popen("ls /mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7"):lines() do if string.find(i,"%.*$") then print(i) end end
this will print out all the file in root diractory and subdiratory.
Output:
0020111118223425.lvf 2012 2012 (2009).mp4 3 Idiots Aashiqui 2 Agneepath.mkv Avatar (2009) Captain Phillips (2013) Cocktail
I want output like:
/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/0020111118223425.lvf [File in Root Directory] /mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/2012/2012.mkv /mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/2012 (2009).mp4 [File in Root Directory] /mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/3 Idiots/3 Idiots.mkv /mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/Aashiqui 2/Aashiqui 2.mkv /mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/Avatar (2009)/Avatar (2009).mkv /mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/Captain Phillips (2013).mkv /mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/Cocktail/Cocktail.mkv
EDIT: I have used this all but its not working with my code in LUA.
when I used with my code it displays wrong directory
for i in io.popen("ls -d $PWD/* /mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7"):lines() do if string.find(i,"%.*$") then print("/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7/"..i) end end
is not finding files in "/mnt/mediashare/net/192.168.1.220_STORAGE_1d1b7" insted its prints the machines root directory files.
The answer is the pwd command, which stands for print working directory. The word print in print working directory means “print to the screen,” not “send to printer.” The pwd command displays the full, absolute path of the current, or working, directory.
An absolute path is the full path to a file or directory. It is relative to the root directory ( / ). Note that it is a best practice to use absolute paths when you use file paths inside of scripts. For example, the absolute path to the ls command is: /usr/bin/ls .
Display your path environment variable. You can use echo $PATH to find which directories your shell is set to check for executable files. To do so: Type echo $PATH at the command prompt and press ↵ Enter . This output is a list of directories where executable files are stored.
A path that starts with / starts in the root directory. For example, /usr/bin/ls is a file called ls in the directory called bin in the directory called usr in the root directory. (It is the executable code for the ls command.)
You can use
ls -lrt -d -1 "$PWD"/{*,.*}
It will also catch hidden files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With