Skip to content

Instantly share code, notes, and snippets.

@freakdesign
Last active March 17, 2022 14:43
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save freakdesign/a1636414cce682c2c444 to your computer and use it in GitHub Desktop.
Save freakdesign/a1636414cce682c2c444 to your computer and use it in GitHub Desktop.
Get a CSV list of all files within the Files section of a Shopify account
/*
Get a list of all files within the Shopify Admin (/admin/settings/files)
This needs to be run within the Chrome Browser. Paste into the debug console and run...
A text file will download when done.
*/
(function(){
var debug = false; // enable logging
var fileArray = [];
var saveList = function(fileArray){
console.log('============ DONE. DOWNLOAD FILE ============');
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
var blob = new Blob(["\ufeff",fileArray],{type:'text/plain'}),
link = window.URL.createObjectURL(blob);
a.href = link;
a.download = 'shopify-files-list' + '.txt';
a.click();
window.URL.revokeObjectURL(link);
};
var getFiles = function(url){
if(typeof(url) === 'undefined'){ var url = '/admin/settings/files?limit=250' }
$.ajax({
url: url,
success: function(d){
var html = $(d);
var fields = html.find('.next-input.next-input--readonly');
for (var i = 0; i < fields.length; i++) {
if(debug){ console.log('Adding ' + fields[i].value) }
fileArray.push(fields[i].value);
};
var next = html.find('#pagination-links li:last a');
if(!next.length || next.hasClass('disabled')){
if(fileArray.length){ saveList(fileArray) }
return;
}
var nextUrl = next[0].href;
console.log(nextUrl)
if(nextUrl.indexOf('direction=next')>-1){
if(debug){ console.log('Fields grabbed. Next page now...') }
getFiles(nextUrl);
}else{
saveList(fileArray);
}
}
});
}
getFiles();
})();
@aungar93
Copy link

Hi, looks like this has stopped working now. Would you be able to update please?
Thanks

@Hujjat
Copy link

Hujjat commented May 4, 2021

Seems like jquery is not anymore on Shopify Admin

Here is the fix.

Before running the above code, you can add jquery to console

fetch('https://code.jquery.com/jquery-latest.min.js').then(r => r.text()).then(r => eval(r))

Might help others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment