Is there a way to get file names from a folder, without loading all the files themselves?

I have 500 videos in a folder in Files on device in my iPad and another copy in iCloud. I was trying to check that the contents matched. I can do this visually in the Files app but I was trying to automate it with Shortcuts.
Is there away of getting the contents of a folder without loading all the files? Just the file names so it runs quickly.
(The on device copy is so I don’t have to wait for downloading with a slow connection and the iCloud copy is a backup)

You could use the ls command and output the list of files into a document. I haven’t used this for a while but this is the command that I’ve used in the past

ls > filelist.txt

Just navigate to the folder you want to list the contents of in the terminal first. Running the command above will generate the text file in the same folder.

If I recall correctly you can alter the path of where the text file is stored.

ls > ~/Desktop/filelist.txt

The above command should save the file to the desktop from what I remember. I haven’t used this for several years but I think I’ve got the commands correct.

There is a dedicated action for this: “Obtenir le contenu du dossier” in french.
I don’t know it name in english.

… if @peasouper was using a Mac, then this would be easy, but they have specifically noted they are using an iPad and that they are comparing iCloud files to files on the iPad.

However, my first thoughts were exactly along these lines, and I’ll come back to this approach below.

I believe this will be “Get Contents of Folder” in English (file (dossier) and folder are fairly synonymous in this respect I believe due to the paper files and folders both being known as dossiers.

However, getting the contents downloads the contents, which I suspect is what @Peasouper has tried and is what has slowed things down, and why they are asking for a solution without loading all the files.


I don’t have large volumes of files to test with, but I was thinking along the same lines as @darranwest in that what we want is to just work with the listing. While the iPad does not come with a local and native Terminal app (imagine the mischief we could get up to with that :imp:), there are a-Shell and iSH Shell - both free on the app store.

You may be able to do this with either, but I confirmed it using iSH Shell.

I decided to try out a file listing by mounting my Shortcuts iCloud directory in the app. Mounting is just adding it to the app’s available file system, the same way plugging in a USB drive on a Mac or PC gives you access to the files on that device.

First of all I issued a command to create a folder in the current folder to be the mount point for the Shortcuts folder.

mkdir sc

Then I issued the command to mount part of the iOS file system to that location.

mount -t ios . sc

This triggers the app to launch the file provider selection for a folder. I navigate to iCloud, go into the Shortcuts folder and tap on the Open option at the top.

From that point, the Shortcuts files are available in that folder location.

I can then, for example, change into that folder and get a file listing using the following commands (one being the ls mentioned earlier.

cd sc
ls

On this basis, I would suggest mounting both areas of the file system into iSH Shell, and then producing a listing for each folder/mount point. The only difference is I would change it to force a single column listing and output to a file as per the suggestion by @darranwest.

Assuming a folder called local1 has been used for the local files and icloud2 has been used for the iCloud files, from the folder containing these I would run the following commands.

ls -1 local1 > local1.txt
ls -1 icloud2 > icloud2.txt
diff local1.txt icloud2.txt

This should output a comparison of the two file listings.

The one BIG caveat here is I don’t know for sure if iOS behind the scenes forces a download of those mount points - specifically the iCloud one. I don’t see everything suddenly not having the re-download icon against them in Files, but sometimes what you see isn’t quite what you get. Assuming it is not downloading the conetnt I would offer this as a mostly automated solution. You could put the commands in a shell script if you are going to run it regularly to fully automate it, but you will need to go into the app to run it as iSH Shell does not currently have Shortcuts or x-callback-url support.

a-Shell does have Shortcuts support. If you really want to be able to run this via a shortcut, I would suggest trying a-Shell. I haven’t tried much of the above with it, but a-Shell doesn’t seem to have mount. Instead it has pickFolder, which works similarly - but not quite the same.

You might have to play around with how it works as when I tried it, it stopped on the second pickFolder of a script something like this:

pickFolder
ls -1 local1 > ~/Documents/local1.txt
pickFolder
ls -1 icloud2 > ~/Documents/licloud2.txt
cd ~/Documents
diff local1.txt icloud2.txt

There may not be a way to fully automate it like that, but I haven’t ruled out a workaround being possible. But this was why I put forward iSH Shell as the way I was approaching it. There might be some other local shell apps out there that could do everything required … I just don’t recall coming across any.

Anyway, I hope that walkthrough makes sense and helps in some way.

Thanks everybody especially sylumer for your time. I do have a-shell on my iPad but have never used it. Although I have made huge shortcuts I’ve always found coding frustrating. I was hoping for a simple Shortcuts setting but I’ll give it a go when I have time using your guide. Much appreciated.

This does it with a-Shell or a-Shell mini:

https://www.icloud.com/shortcuts/0265946dc3b249ea81b71e155d0e789a

Hello,
Sorry, but I think there is no load of content but only files details.
Test: about same time response with 10ko and 200Go folder.
If I’m wrong, it’s meaning that my iPad (and shortcuts) read 10ko and 200Go at the same speed!
Thanks to return.

PS: sorry for my English, but I think -because I struggle each (often never) times I try to do a shortcut- it miss a [good] reference guide for all Shortcuts actions (with examples for example); so if there is a LOT (because I’m not an expert at all for Shortcuts) volunteers, I’m ready to compute all examples -AND doc&tips- and try to do a reference guide on the site; or perhaps on Trello.

Certainly faster for me operating on files on device vs files that are offline on iCloud using that acton. Any chance all of your iCloud files are already on device?

Yes, OK, you are right, on cloud: it loads (perhaps) the content and it is an infinite time.

Oups, sorry: same time locally or iCloud.
But on tiers (google, Microsoft, …), infinite time: perhaps no rights?

Works perfectly. Thank you very much