Jump to content

opening a file with a partially known filename


asaschool

Recommended Posts

Hey everyone,

I have a problem with trying to open a zip file that has a changing name. The file always starts with the same first 4 letters and an underscore followed by 4 random letters or numbers and always ends in .zip:

 

Example:

FILE_DG01.zip - Today

FILE_9044.zip - Tomorrow

FILE_809P.zip - Next Day........

 

I use the following simple script to extract the files and move them to another directory where I use them in my applications:

 

<?php

$zip = zip_open("FILENAME.zip");

if ($zip) {

while ($zip_entry = zip_read($zip)) {

$fp = fopen("DIRECTORY".zip_entry_name($zip_entry), "w");

if (zip_entry_open($zip, $zip_entry, "r")) {

$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

fwrite($fp,"$buf");

zip_entry_close($zip_entry);

fclose($fp);

}

}

zip_close($zip);

}

?>

 

I have looked everywhere for an answer and I am sure that I am looking in the wrong places for the solution to this. Any help is appreciated.

 

Thanks

Link to comment
Share on other sites

That would be easier. I dont label the files I just access and use them. I was told that the server generates these names. I log on to a third-party server and extract files to use in some of my applications. The main file is labeled with a date but the files inside all conform to the random name. All the files are identifiable and conform the following name structure:  FILE_XXXX.zip

Link to comment
Share on other sites

I'm confused.  Is it the zip file with the random name?  Or is it the files INSIDE the zip file that have random names?

 

What files are you trying to process?  If you're trying to process the zip file, how are the zip files retrieved?  Are YOU retrieving them from this third party server?  Does one of YOUR scripts retrieve them form the other server?

 

If the script is being retrieved by you or your script, you could give it whatever name you wanted.

Link to comment
Share on other sites

ok, sorry I need to explain this better. What I need to do is copy files located on a remote FTP server and move them to my local server. When I move these files I rename them and place them in their proper directories. I already have a script that executes this. Inside of the files I moved to the local server are four zip files that have the random names and all of them need to be unzipped. All of them start with a unique title followed by _ and the four random digits. There is no rhyme or reason to the random digits.

 

Is there a way to unzip all of the files inside the file that I moved to the local server in one script? If so should I use a foreach statement? I'm using the code I entered earlier to unzip specific files but it will not unzip a directory full of zips.

 

Example:

remote_file.zip------file copied and moved---->renamed_file_on_local.zip (this is completed and working)

 

contents of: renamed_file_on_local.zip

FILE1_XXXX.zip------file copied and moved--->unzipped (I can do this if the zip name is known, but it changes daily)

FILE2_XXXX.zip

FILE3_XXXX.zip

FILE4_XXXX.zip

 

contents of: zipX.zip

files i need

 

Thanks again for all your input

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.