Checking for file extensions
I have a form that I want to submit a csv file to, however I would like to check the file to make sure that it is indeed .csv before I perform the task that I need to do
*****************Example***********************
form.html
<form name=vo_verify action=verify.jsp method=post>
<input type=file>
<input type=submit>
</form>
verify.jsp
return true == .csv
return false != .csv
Could you do a check for the substring within the filename?
Like,
String filename = (String)request.getParameter("file");
int index = filename.indexOf(".csv");
if (index == -1) do something; //extension .csv not found
else do something else;
There might be a better way to do this, but this should work I think.
Also, bdtjdc was just trying to help, which is what this forum is for. :)
Similar Messages
-
Checking for files in a folder -- Wrong output
Hi guys,
I'm writing a simple program, I have to check for 6 files (hardcoded, they will never change) if they are in certain directories/paths.
The problem is, I think I have a problem in my IF statements, because it continueally returns false.
The paths are on networked drives, does that make a difference?
I'm rather stuck on this one, any help would be appreaciated.
(some paths/file names have been replaced by "xxxxxxxxx", for security)
* Checks for files in a directory, prints results.
* @author Mitchell
* @version 0.2
* @date 28 Jul '05
import java.awt.*;
import java.io.*;
import java.lang.Object;
import javax.swing.*;
import java.util.*;
public class FileCheck extends JFrame
//declare filenames/paths, add more if needed.
String fileName1 = "file it2_load.txt";
String fileName2 = "mo_batch.txt";
String fileName3 = "mo_bcp.txt";
String fileName4 = "mo_load.txt";
String fileNameX = "IT2_1000_yyyymmdd.txt";
String fileNameY = "IT2_2000_yyyymmdd.txt";
//declare directories to search
String fileLocation1 = "\\\\xxxxxxxxx\\aus_bear\\Patrol";
String fileLocation2 = "\\\\xxxxxxxxx\\nz_bear\\Patrol";
String fileLocation3 = "\\\\xxxxxxxxx\\bear\\remote\\RTS";
String fileLocation4 = "\\\\xxxxxxxxx\\bear\\remote\\RTS";
//declares array for filename storage. Change if needed.
File fileNamesArray1[];
File fileNamesArray2[];
File fileNamesArray3[];
File fileNamesArray4[];
//set path to find files
File filePath1 = new File(fileLocation1);
File filePath2 = new File(fileLocation2);
File filePath3 = new File(fileLocation2);
File filePath4 = new File(fileLocation2);
//string buffer to store results
StringBuffer results = new StringBuffer();
//start of FileCheck method
public FileCheck()
//collects all filenames from pre-set path1
fileNamesArray1 = filePath1.listFiles();
results.append("This program checks for files in given folders."
+"\nTRUE = File does exist in folder."
+"\nFALSE = File does not exist in folder.\n\n");
results.append(fileLocation1 + "\n");
//start for loop1 - check for pre-set filenames in path1
for(int i=0; i < fileNamesArray1.length; i++)
if( fileName1.equals(fileNamesArray1.toString()))
results.append("PATH1 >> " + fileNamesArray1[i] + " >> TRUE\n" + fileNamesArray1[i].lastModified());
else if( fileName2.equals(fileNamesArray1[i].toString()))
results.append("PATH1 >> " + fileNamesArray1[i] + " >> TRUE\n" + fileNamesArray1[i].lastModified());
else if( fileName3.equals(fileNamesArray1[i].toString()))
results.append("PATH1 >> " + fileNamesArray1[i] + " >> TRUE\n" + fileNamesArray1[i].lastModified());
else if( fileName4.equals(fileNamesArray1[i].toString()))
results.append("PATH1 >> " + fileNamesArray1[i] + " >> TRUE\n" + fileNamesArray1[i].lastModified());
else
results.append("PATH1 >> " + fileNamesArray1[i] + " >> FALSE\n");
} //end for loop1
//collects all filenames from pre-set path2
fileNamesArray2 = filePath2.listFiles();
results.append("\n" + fileLocation2 + "\n");
//start for loop2 - check for pre-set filenames in path2
for(int j=0; j < fileNamesArray2.length; j++)
if( fileName2.equals(fileNamesArray2[j].toString()))
results.append("PATH2 >> " + fileNamesArray2[j] + " >> TRUE\n" + fileNamesArray2[j].lastModified());
else if( fileName2.equals(fileNamesArray2[j].toString()))
results.append("PATH2 >> " + fileNamesArray2[j] + " >> TRUE\n" + fileNamesArray2[j].lastModified());
else if( fileName3.equals(fileNamesArray1[j].toString()))
results.append("PATH2 >> " + fileNamesArray2[j] + " >> TRUE\n" + fileNamesArray2[j].lastModified());
else if( fileName4.equals(fileNamesArray1[j].toString()))
results.append("PATH2 >> " + fileNamesArray2[j] + " >> TRUE\n" + fileNamesArray2[j].lastModified());
else
results.append("PATH2 >> " + fileNamesArray2[j] + " >> FALSE\n");
} //end for loop2
//collects all filenames from pre-set path1
fileNamesArray3 = filePath3.listFiles();
results.append("\n" + fileLocation3 + "\n");
//start for loop3 - check for pre-set filenames in path1
for(int k=0; k < fileNamesArray3.length; k++)
if( fileNameX.equals(fileNamesArray3[k].toString()))
results.append("PATH3 >> " + fileNamesArray3[k] + " >> TRUE\n" + fileNamesArray3[k].lastModified());
else
results.append("PATH3 >> " + fileNamesArray3[k] + " >> FALSE\n");
} //end for loop3
//collects all filenames from pre-set path4
fileNamesArray4 = filePath3.listFiles();
results.append("\n" + fileLocation4 + "\n");
//start for loop4 - check for pre-set filenames in path1
for(int l=0; l < fileNamesArray4.length; l++)
if( fileNameY.equals(fileNamesArray4[l].toString()))
results.append("PATH4 >> " + fileNamesArray4[l] + " >> TRUE\n" + fileNamesArray4[l].lastModified());
else
results.append("PATH4 >> " + fileNamesArray4[l] + " >> FALSE\n");
} //end for loop4
//construct displaybox for results
JTextArea textArea = new JTextArea( results.toString() );
textArea.setEditable(false); //disables modification of results
Container container = getContentPane();
container.add( new JScrollPane( textArea ) );
setSize( 500, 500 ); // set window size
setVisible( true ); //allow visibility
//main
public static void main (String args[])
FileCheck window = new FileCheck();You could try using the File.exists() method.
The paths are on networked drives, does that make a difference?Try the above on a local file and a networked file.
I'm writing a simple program, Actually a simple program would be something like:
File file = new File("xxx");
System.out.println(file.exists());No need to include all the code you posted.
http://www.physci.org/codes/sscce.jsp -
Formatted Text field for File Extensions
Hi guys,
Is it possible to create formatted text field for file extension like it should accept *.bmp, .bmp, bmp. etc..... It is not necssary to be a Combo Box. TextField will work.
Thanks in advance.
AZGHARAny one here \Help\Help\Help ;-(
-
Pacman hanging on "checking for file conflicts"
I've tried running pacman -Syu on my laptop and pacman is simply hanging at the checking for file conflicts stage. I've let it sit for several minutes, but it never seems to get past that stage. The list of packages to be updated isn't long:
Targets (5): bison-2.6.2-1 chromium-21.0.1180.75-1 flex-2.5.37-1 libldap-2.4.32-1 lm_sensors-3.3.2-4
This is being done on a laptop that was only recently rebuilt with a new Arch install using the latest installation media. The install went well and previous updates have worked with no problems.I'm glad you solved the problem but "pacman -Scc" shouldn't be necessary and makes it more difficult to recover in a variety of situations. You can always re-download old packages but having them in your cache makes it easy to roll something back and makes it possible to do this without, for example, a working network connection. I installed in November and I've never even run "pacman -Sc" let alone "pacman -Scc". (Though I have trimmed the cache to free up disk space using, I think, paccache.)
-
Checking for file conflicts: could not get filesystem information
When I try to install a new package with pacman 4 I got the following warning just after pacman has done "checking for file conflicts":
warning: could not get filesystem information for /var/lib/ntp/etc/resolv.conf (deleted): No such file or directory
After the warning message is printed, the installation continues normally. This warning message has never shown up before.
I have ntpd running in a chroot as a non-root user (instructions).
I am wondering if anyone else gets the same warning message and if this 'problem' can be solved.
I forgot to say: the file is still there according to ls and is not empty, but the contents differs form the /etc/resolv.conf-file.
tim@tim-notebook:~$ cat /var/lib/ntp/etc/resolv.conf && echo && cat /etc/resolv.conf
# Generated by NetworkManager
# Generated by NetworkManager
nameserver 192.168.1.1
Last edited by timothy (2012-01-19 00:15:51)I'm not sure how to do that or I do not know exactly what you mean.
tim@tim-notebook:~$ pkgfile -gs "*etc/resolv.conf"
core/filesystem
extra/archboot
But you probably already knew that.
Running pacman with the --debug option did not gave me any more clues. All I know now, is that this message is printed when the moundpoints are examined:
stderr 'pacman -Syu--debug' output wrote:(...)
debug: checking possible conflict: /var/lib/
debug: file is a directory, not a conflict
debug: checking available disk space
warning: could not get filesystem information for /var/lib/ntp/etc/resolv.conf (deleted): No such file or directory
debug: mountpoint: /var/lib/ntp/proc
debug: mountpoint: /var/lib/ntp/lib
debug: mountpoint: /var/lib/ntp/etc/services
debug: mountpoint: /tmp -
[solved] pacman 4 hangs after "checking for file conflicts"
Like others, I removed yaourt and package-query because they conflicted with pacman4... not worried about that, I'll reinstall them later.
I put the new pacman.conf in place (my old one wasn't really customized). I left SigLevel = Never.
Now, I can run pacman -Sy fine, but if I try to install anything, I it just hangs:
sudo pacman -S audacity
resolving dependencies...
looking for inter-conflicts...
Targets (1): audacity-1.3.14-2
Total Download Size: 3.21 MiB
Total Installed Size: 15.29 MiB
Net Upgrade Size: -0.00 MiB
Proceed with installation? [Y/n]
:: Retrieving packages from extra...
audacity-1.3.14-2-x86_64 3.2 MiB 1397K/s 00:02 [###########################] 100%
(1/1) checking package integrity [###########################] 100%
(1/1) loading package files [###########################] 100%
(1/1) checking for file conflicts [###########################] 100%
I've waited up to 20 or 30 minutes and nothing happens. It's not just audacity, any package I try to install does this.
Suggestions?
Last edited by TheAmigo (2012-01-17 18:55:38)With --debug switch it prints:
checking for file conflicts...
debug: looking for file conflicts
debug: searching for file conflicts: coreutils
debug: searching for filesystem conflicts: coreutils
debug: searching for file conflicts: ethtool
debug: searching for filesystem conflicts: ethtool
debug: searching for file conflicts: fail2ban
debug: searching for filesystem conflicts: fail2ban
debug: searching for file conflicts: gpgme
debug: searching for filesystem conflicts: gpgme
debug: searching for file conflicts: vim-runtime
debug: searching for filesystem conflicts: vim-runtime
debug: searching for file conflicts: gvim
debug: searching for filesystem conflicts: gvim
debug: searching for file conflicts: hdparm
debug: searching for filesystem conflicts: hdparm
debug: searching for file conflicts: inetutils
debug: searching for filesystem conflicts: inetutils
debug: searching for file conflicts: lib32-glibc
debug: searching for filesystem conflicts: lib32-glibc
debug: searching for file conflicts: lib32-gcc-libs
debug: searching for filesystem conflicts: lib32-gcc-libs
debug: searching for file conflicts: lib32-glib2
debug: searching for filesystem conflicts: lib32-glib2
debug: searching for file conflicts: lib32-gdk-pixbuf2
debug: searching for filesystem conflicts: lib32-gdk-pixbuf2
debug: searching for file conflicts: lib32-pango
debug: searching for filesystem conflicts: lib32-pango
debug: searching for file conflicts: lib32-gtk2
debug: searching for filesystem conflicts: lib32-gtk2
debug: searching for file conflicts: linux
debug: searching for filesystem conflicts: linux
debug: searching for file conflicts: nspluginwrapper
debug: searching for filesystem conflicts: nspluginwrapper
debug: searching for file conflicts: nvidia
debug: searching for filesystem conflicts: nvidia
debug: searching for file conflicts: qtwebkit
debug: searching for filesystem conflicts: qtwebkit
debug: searching for file conflicts: rpcbind
debug: searching for filesystem conflicts: rpcbind
debug: searching for file conflicts: unrar
debug: searching for filesystem conflicts: unrar
debug: searching for file conflicts: xscreensaver
debug: searching for filesystem conflicts: xscreensaver
checking available disk space...
debug: checking available disk space
Without the --debug switch
Proceed with installation? [Y/n]
(21/21) checking package integrity [############################] 100%
(21/21) loading package files [############################] 100%
(21/21) checking for file conflicts [############################] 100%
Note that the 'checking available disk space...' is not printed without the --debug option although it doesn't look like being 'debug output'.
I don't see much disk activity after that and the pacman process uses no CPU time and the process status goes to D in `ps` (man ps says: D: Uninterruptible sleep (usually IO)).
Last edited by drrossum (2012-01-18 21:58:28) -
[solved] "pacman -Syu" hangs after "checking for file conflicts"
This is my third attempt. I let it run yesterday for 20 hours on the theory that maybe it was actually doing something. It always completes "checking for file conflicts" but never goes any further.
Does anyone have any suggestions how to get it to continue?
[ken@xxxxx ~]$ sudo pacman -Syu
:: Synchronizing package databases...
core is up to date
extra 1421.6 KiB 2.03M/s 00:01 [######################] 100%
community 1775.0 KiB 3.00M/s 00:01 [######################] 100%
:: Starting full system upgrade...
resolving dependencies...
looking for inter-conflicts...
Targets (27): binutils-2.23-1 coreutils-8.20-1 cryptsetup-1.5.1-1
device-mapper-2.02.98-1 emacs-24.2-2 filesystem-2012.10-2
firefox-16.0.2-1 gcc-4.7.2-2 gcc-libs-4.7.2-2 glibc-2.16.0-5
hwids-20121022-1 imagemagick-6.8.0.3-1 libidn-1.25-1
libwbclient-3.6.9-1 linux-api-headers-3.6.3-1 lvm2-2.02.98-1
mkinitcpio-0.11.0-1 nspr-4.9.3-1 nss-3.14-1
nss-myhostname-0.3-3 smbclient-3.6.9-1 systemd-195-2
thunderbird-16.0.2-1 tzdata-2012h-1 util-linux-2.22.1-2
wget-1.14-2 xulrunner-16.0.2-1
Total Download Size: 47.80 MiB
Total Installed Size: 550.57 MiB
Net Upgrade Size: 6.43 MiB
Proceed with installation? [Y/n] y
:: Retrieving packages from extra...
libwbclient-3.6.9-1... 19.5 KiB 407K/s 00:00 [######################] 100%
smbclient-3.6.9-1-x... 7.9 MiB 2.71M/s 00:03 [######################] 100%
thunderbird-16.0.2-... 17.1 MiB 2.92M/s 00:06 [######################] 100%
xulrunner-16.0.2-1-... 22.9 MiB 2.92M/s 00:08 [######################] 100%
(27/27) checking package integrity [######################] 100%
(27/27) loading package files [######################] 100%
(27/27) checking for file conflicts [######################] 100%
Last edited by KenJackson (2012-10-30 14:25:05)Allan wrote:Can you run with --debug?
OK. That garnered an additional piece of info. Here's the end of the long output:
debug: searching for filesystem conflicts: wget
debug: searching for file conflicts: xulrunner
debug: searching for filesystem conflicts: xulrunner
checking available disk space...
debug: checking available disk space
Disk space? I think I have enough disk space.
[ken@xxxxx ~]$ df
Filesystem Size Used Avail Use% Mounted on
rootfs 47G 11G 34G 25% /
dev 2.0G 0 2.0G 0% /dev
run 2.0G 292K 2.0G 1% /run
/dev/sda3 47G 11G 34G 25% /
shm 2.0G 140K 2.0G 1% /dev/shm
/dev/sda1 99M 21M 74M 22% /boot
/dev/sda4 72G 1.9G 66G 3% /home
Is disk space really the problem? Or is that just where it hung? -
No OK Button For File Extension In Preferances! Help!
I have an external hard drive, which I put all of my media on. However, whenever I put a CD or download from the Itunes music store it doesnt save on this hard drive. I found a way to change where the files go for when I download or import through Itunes (Edit, Preferances) but there is no OK button at the bottom of the screen so the only thing I can do is X it out and it doesnt save any changes. Please help, my computer is too old, it holds 9 gigs, I can't save the music I listen to on it, so please help, thanks.
Hello,
please see the answer in
http://stackoverflow.com/questions/17757248/error-there-is-no-script-engine-for-file-extension-vbs-when-using-git-bash
"make sure that .vbs files have Microsoft Windows Based Script Host set as the current default program."
Best regards
Meinolf Weber
MVP, MCP, MCTS
Microsoft MVP - Directory Services
My Blog: http://blogs.msmvps.com/MWeber
Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.
Twitter: -
Check the file extension in the selection screen
hi,
in the selection screen i am giving a file path. the file should be of type PDF only.
how to validate it ?
i am splitting the file path at "." and checking for the last three letters , if it pdf or not.
but it is throwing error for pdf format also.
throw some light on it and let me know.
thanks and regards.
sukihi,
You need to pass only COMPLETE_FILENAME
say C:\ABC\A\ABC.TXT
data : v_filename type PCFILE-PATH.
v_filename = "C:\ABC\A\ABC.TXT".
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
COMPLETE_FILENAME = v_FILENAME
IMPORTING
DRIVE = v_DRIVE
EXTENSION = v_EXTENSION
NAME = v_name
NAME_WITH_EXT = v_namewithtxt
PATH = PATH_VALUE
EXCEPTIONS
INVALID_DRIVE = 1
INVALID_EXTENSION = 2
INVALID_NAME = 3
INVALID_PATH = 4
OTHERS = 5.
you will get the output as
DRIVE C
EXTENSION TXT
NAME ABC
NAME_WITH_EXT ABC.TXT
PATH \ABC\A\
Hope this helps.
Regards,
Richa -
Support for file extensions with more than three characters when saving - I want my FLAC!
Why does the Wave Editor still drop characters from filenames with more than three character extensions when you save a file? But since -opening- a FLAC file with an extension of ".flac" doesn't get chopped to ".fla", why does Audition still chop off the extra character when -saving-?
It gets old quickly when you have to save, close and reopen files in order to get Audition's Multitrack editor to play nice and be able to find files when you reopen the Session.
Given that the FLAC filter is open source, I may just have to modify the code and recompile it to force a save to ".fla"... But of course, ".fla" is a Flash file extension, which I also use, so that is a crude hack for me.Hi bro...
use in BYTE mode in place of in TEXT mode. and at the end of each line give some special charactor so as to distinguish between lines.This is effected by unicode check too
regards
Edited by: Mohit Kumar on Feb 9, 2009 9:44 AM -
CS5, checked "save file extensions as small case letters" but still capital, why?
hi,
i installed CS5 4 weeks ago, since this time, i never got a file extension in small case letters, only capital letters ( xxx.TIF ). why?
i checked it in preferences, see enclosed screenshot... i never had this problem in CS4.
it would be important for myself, when saving files, that alle extensions are small case letters, like xxx.psd or xxx.eps
usually i rename these extensions manually, cause i am uploading final images to PC servers, which
cant recognize capital letters, i presume....no, i am still dealing with this problem on both macs,
mac pro mid 2010 2,8 quad (24GB RAM) and my mbp 15" i7 (4GB RAM)
where i installed Photoshop CS5.
on both macs, photoshop always saves files with capital letter file extensions (xxx.TIF or xxx.PSD)
thats very annoying, as i have to manually rename the file in the finder later.
and thats for all files i create.
i really wonder, could anyone from the adobe staff please comment if it is a bug
or anything else?
thanks! -
Checking for files using infoview
Hi
I am new to use Infoview in BO. In my project they are scheduling CR in infoview for a particular time. now new requirement is :
On nightly basis files will be send for each region.once they are loaded message will be generated using script in unix. Now my part is to login to the unix server and check for the message(access to the path will be provided. message may be content in file or may be a touch file.not my part) and the schedule timing through infoview and should run the report.
To schedule report for a particular time i went into schedule option and given database details where CR is present,destination details to where it need to be ftped and the format of output and timine on which the report need to be run.
But i dont know the process how to login to unix server and check for message.
Please let me know is there any option for the baove requirement in infoview.
Thanks in advance.CMC is the administration console. I would recommend to take a look at the following document:
http://help.sap.com/businessobject/product_guides/boexir2/en/xir2_bip_Admin_en.pdf
Start at page 200.
Regards,
Stratos -
Checking for file whether it is excel file or not??
when ever we r download or upload a file we never check for its type...
like when gui_upload fm used then it should be text file ....or
when alsmex_excel_to_internal_table fm used by default check its have 2 be excel file...
but my recomend is when ever download/upload a file its checking its type....
if .xls file then alsmex_excel_to_internal_table fm runs or if .txt then gui_upload runs...
need some type of file checking..
Thanks & regards ,
Sagnik RoyCALL FUNCTION '/SAPDMC/LSM_PATH_FILE_SPLIT'
EXPORTING
pathfile = lf_path "<--Your file path
IMPORTING
pathname = lf_path
filename = lf_name.
CHECK lf_name IS NOT INITIAL.
CALL FUNCTION 'TERM_TRANSLATE_TO_UPPER_CASE'
EXPORTING
langu = sy-langu
text = lf_name
IMPORTING
text_uc = lf_name
EXCEPTIONS
no_locale_available = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
IF lf_name CA '.'.
sy-fdpos = sy-fdpos + 1.
IF lf_name+sy-fdpos(*) = 'TXT'(044).
"<---Call your upload fm here
ELSEIF lf_name+sy-fdpos(*) = 'XLS'(045).
"<---Call your upload fm here
ENDIF.
ENDIF. -
Use thread to check for file exists. How?
public class FileSearcher extends Thread
String name = "Unknown";
//RunFileSearcher rfs = new RunFileSearcher(name);
//FileSearcher rfs = new FileSearcher(name);
File f = new File();
Thread t = new Thread(); // create the thread
t.start(); // start the thread running
public void run(name)
if( f.exists(name) )
System.out.println("*** File " + f + " has been created. ***");
else
System.out.println("Searching for file " + f) ;
}How do I use each thread to check for each file exists per sec??
Please Help Thanks1) Why are you using Threads?
2) It is preferrable to implement Runnable.
3) This is all incredibly pointless (see point 1) -
Authorization check for files.
Hi
All,
Which function module would you use to check the users authorization to access files before opening a file ?
Thanks N Regards
Priya.Hi,
If your requirement is for application server files I wouldn't use a function module at all. I would use the ABAP statement AUTHORITY-CHECK with the object S_DATASET.
Regards,
Nick
Maybe you are looking for
-
S4 Sync settings for email no longer available after update
After the Verizon Galaxy S4 Kit Kat update: I can no longer sync my email accounts. I get a "email sync turned off" message. when I go to the SYNC settings (stttings-accounts-email-settings-account settings-sync settings) there is NO option to turn s
-
My iPhone 5s can no longer use Internet on a wifi network. I've reset everything, how can I roll back to iOS 7? i Was considerinf buying a macbook pro, but am reconsidering spending such an amount of money on a company that can screw up such a basic
-
How I can contact with my carrier. I bought my iphone from USA and now I am in another country
-
Javascript Typewriter Tool in Acrobat
Hi All, I am about to embark on a project for Batch Processing using Javascript, I am an extreme novice and do not know whether I am going down the right path. Does anyone know if the Typewriter tool can used via Javascript on Batch level, and what S
-
Keyword Search showing too many photos
I have over 22,000 photos and over 300 keywords for them. Sadly I cannot search by keyword since the keyword list only shows the last 146 keywords on the screen (a known bug that, in my case, only shows keywords beginning with p-z) and there is no w