Thursday 15 May 2014

perl populating arrays with filenames from user defined directory? -


I'm trying to populate two arrays with file names from a user-defined directory I'm still working Yes, if the file is in the same directory where I am running the program. The final goal of this code is to convert a file from one format to another using the script, and export a new defined file to the user-defined directory.

  # export directory to my $ export_dir = $ argv [0] "\\". Print "export directory: \" $ export_dir \ "\ n \ n" if DEBUG; # Get the current working directory my $ cwd_dir = getcwd; # Change the slash with slash for Windows compatibility $ cwd_dir = ~ s / \ // \\ / g; Print "current work directory: \" $ cwd_dir \ "\ n \ n" if DEBUG; # Get a list of zip files in the directory my @zip_files = glob "* .zip";   

This code works when the zip file is in the current working directory. How can I work it where the zip file is in a user-defined directory? (In this case, a subfolder, but where the user defines the export directory).

Just enter the name of the directory in a previous glob device:

  My @zip_files = glob "$ export_dir \\ * .zip";   

Ideally, you should use the file :: device CPAN module to create file paths in OS-independent mode, link-coding < Code> "\\" for Windows and "/" for UNIX.

No comments:

Post a Comment