find and remove unwanted png files from var/import/images folder on remote linux server - duplicates

I have a csv file that contains the filenames of all active product images in use on my live site.
I wish to remove any files from the var/import/images folder that does not have a matching name from the csv doc I possess.
Can someone suggest a method to achieve my goal?

Related

How can I save two files with the same name inside the same folder, without renaming any using php?

How can I save two files with the same file name in the same folder without renaming anyone using php?
For instance: A user has an audio file name "first.mp3"; and another user uploads another file named: "first.mp3"; and I want to save these two files without renaming any so that when people are downloading the audio from the front end, the name does not change.
I can do this by concatenating a random number to differentiate the files but I want to beat this method of renaming.
Should I be saving each file inside a unique folder and save the file names to database? but this method will create too many folders which i don't think it is appropriate.
You cannot have two files with the same name in the same folder.
You would either have to add a random string to the end of each file like you suggest or save each user's files in a directory allocated to their account.
Regards,
Leslie
Saving multiple files with the same name within the same folder is just not possible.
I'd opt for a strategy that would involve saving the original filename somewhere (in a database, for example) along with the name/path of the actual file. When the User downloads the file (presumably through a web app of some sorts), you can set the name of the file via headers with your language of choice.
You could even rename the files to something completely random when they're uploaded so you can have them all in one folder - as long as you store the original filename somewhere, you can always set it before you serve it back to the end user.

I want to find some files that includes some keyword and copy it to other folder

I want to find files that includes some keyword and copy it to other folder.
So I need two features.
Find files by keyword and list it at "file" type value.
copy the file to different directory.
But Google drive supports same folder name so I don't know how to targeting folder by name. And I want copy the file only if there is not file has same name. Because I'll run this script every 5 minutes and if I don't set about that, there are many same name files to target directory.
How can I do this?
AFAIK, the only supported methods that you can use to get files in Class DriveApp are:
getFileById(id)
getFiles()
getFilesByName(name)
getFilesByType(mimeType)
Then, to make a copy to other folder, you can use the following methods that are given in Class File
makeCopy(destination)
makeCopy(name, destination)
Lastly, the suggested solutions given in this SO post might also help.

turn folder into a zip file

I have a folder on my desktop and i want to convert it into a .zip file. It shouldnt ask me were to save it but just save it straight to my desktop or any folder i specified.
I tried ASZip, fZip etc. but i can't get it to work. There isn't any of them that seem to let me just add a folder and zip it.
I was only able to create a byteArray wit ASZip but when i saved it, it left me with a file that was not able to be opened.
Would it be possible to achieve what i want without the use of an external library?
Any help would be appreciated.
You can't actually zip a folder but you can zip all the contents inside the folder. You would have to use FileReferenceList to load in flash all the files inside the folder.
FileReferenceList allows you to have multiple selection in the browse window.
Then you would have to pass all these files to the zip managing library and get a ByteArray from it.
This byte array you would localy dump inside a "yourFileName.zip" by using FileReference.save().
The application cannot save the file to a predetermined location. The user has to pick the location using the "save to" prompt.

JSP File Upload

In my jsp page, I need to upload files, images, Word Documents, Excel sheets, Etc. using a single upload option.
After uploading, I want to place them in a folder which has to be created in user's name(If not exists) within root folder.
Also I need to rename the file into some string like username+serial number.
I should be able to give links to these files for displaying them.
I am new to jsp. please help me.
This tutorial should help you: http://www.roseindia.net/jsp/file_upload/Sinle_upload.xhtml.shtml

Issue in creating Zip file using glob.glob

I am creating a Zip file from a folder (and subfolders). it works fine and creates a new .zip file also but I am having an issue while using glob.glob. It is reading all files from the desired folder (source folder) and writing to the new zip file but the problem is that it is, however, adding subdirectories, but not adding files form the subdirectories.
I am giving user an option to select the filename and path as well as filetype also (Zip or Tar). I don;t get any problem while creating .tar.gz file, but when use creates .zip file, this problem comes across.
Here is my code:
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Also, if I use code below:
for dirpath, dirnames, filenames in os.walk(Source_Dir):
myZip.write(os.path.join(dirpath, filename) os.path.basename(filename))
myZip.close()
Now the 2nd code taks all files even if it inside the folder/ subfolders, creates a new .zip file and write to it without any directory strucure. It even does not take dir structure for main folder and simply write all files from main dir or subdir to that .zip file.
Can anyone please help me or suggest me. I would prefer glob.glob rather than the 2nd option to use.
Thanks in advance.
Regards,
Akash
Glob by design does not expand into subdirectories. It follows UNIX style path rules and expansions see the documentation for fnmatch for more information. If you want to get at the subdirectories you need to add it to the path. This example will get everything at one level down.
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Doug Hellman has an excellent discussion here. If you are not using the pattern features of glob (like *.txt for all text files or *[0-9].txt for all text files that have a number before the extension) then I think your os.walk solution is better